在将字典内容写入文件时遇到了上述TypeError问题:
`>>> dict1={‘a’:1,‘b’:2,‘c’:3}
with open(fpath,‘a’,‘utf-8’)as f:
… f.write(str(dict1))
… f.close()
…
Traceback (most recent call last):
File “”, line 1, in
TypeError: an integer is required (got type str)
`
后来改用
`
import codecs
f=codecs.open(fpath,‘a’,‘utf-8’)
f.write(str(dict1))
f.close()
`
就没有出现上述问题了