【发布时间】:2015-12-28 16:23:49
【问题描述】:
我有这个代码:
import itertools
res = itertools.permutations('abcdefghijklmnopqrstuvwxyz',5) # 5 is the length of the result.
for i in res:
print ''.join(i)
我需要将结果保存在 .txt 文件中,而不是打印 print ''.join(i)。
我不熟悉python。感谢您的宝贵时间!
【问题讨论】:
-
这是非常基本的;一个快速的谷歌已经指向一个教程:docs.python.org/2/tutorial/inputoutput.html
-
您只需打开一个文件对象并将
print替换为fileobj.write(''.join(i) + '\n')。
标签: python python-2.7 python-3.x