0
我有以下代码。我正在尝试使代码将打印保存到文件末尾的文件中。我会错过什么部分?打印到文件?
import itertools
#Open test.txt
file = open('test.txt', 'a')
res = itertools.product('abcdef', repeat=3) # 3 is the length of your result.
for i in res:
print ''.join(i)
有写作和实际的书面文件,打开该文件之间没有任何联系。 –
在Python 2中,其中'print'是一个语句,您需要使用'print''.join(i)>> file'将输出定向到一个打开的文件。在Python 3中它的功能,使用'print(''。join(i),file = file)''。 – martineau