我正在尝试将字典写入invIndex
文本文件。我找到了以下帖子:
我写了这些行:
import csv
f = open('result.csv','wb')
w = csv.DictWriter(f,invIndex)
w.writerow(invIndex)
f.close()
当我到达这一行时:w.writerow(invIndex)
,我收到此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python33\lib\csv.py", line 153, in writerow
return self.writer.writerow(self._dict_to_list(rowdict))
TypeError: 'str' does not support the buffer interface
如何正确地将字典写入文本文件。