fi = open("小女孩.txt","r") ch = "a" dic = {} while ch: ch = fi.read(1) if ch not in ("\n","\r","。","!","?","”",";",""): dic[ch] = dic.get(ch,0)+1 print(dic) fo = open("PY301-1.txt","w") fo.write(dic)
没报错:PY301-1.txt里面内容是空的
fo.write(对象)
这条语句只能成功当“对象”是 str 或 bytes(二进制模式时)。
其它任何“对象”都必须先序列化成字符串/字节