我需要在python中为列表写入一个文件。我知道这个列表应该用join方法转换成字符串,但是因为我有一个元组,所以我感到困惑。我尝试了很多改变我的变量为字符串等,这是我第一次尝试:python将一个列表写入文件
def perform(text):
repository = [("","")]
fdist = nltk.FreqDist(some_variable)
for c in some_variable:
repository.append((c, fdist[c]))
return ' '.join(repository)
,但它给了我下面的错误:
Traceback (most recent call last):
File "<pyshell#120>", line 1, in <module>
qe = perform(entfile2)
File "<pyshell#119>", line 14, in perform
return ' '.join(repository)
TypeError: sequence item 0: expected string, tuple found
任何想法如何写列表“存储库'到一个文件?谢谢!
你应该更好地解释什么是你要回报,这格式的字符串?你想稍后检索元组吗? – 2011-01-11 02:08:47
是应该是某种持久性缓存的存储库? – 2011-01-11 02:11:09