【发布时间】:2016-11-12 01:45:07
【问题描述】:
所以我想做的就是将这个程序的输出保存到一个文本文件中。
import itertools
res = itertools.product('qwertyuiopasdfghjklzxcvbnm', repeat=3)
for i in res:
print ''.join(i)
我正在运行 python 2.7
【问题讨论】:
所以我想做的就是将这个程序的输出保存到一个文本文件中。
import itertools
res = itertools.product('qwertyuiopasdfghjklzxcvbnm', repeat=3)
for i in res:
print ''.join(i)
我正在运行 python 2.7
【问题讨论】:
您可以使用open 然后write 生成文件处理程序的方法。
import itertools
res = itertools.product('qwertyuiopasdfghjklzxcvbnm', repeat=3)
with open('output.txt', 'w') as f:
for group in res:
word = ''.join(group)
f.write(word+'\n')
print(word)
【讨论】: