我已輸入從Numbers.txt文件,並希望寫out.txt文件輸出, 任何人都可以引導什麼錯誤。無法獲取文本文件輸出在Python 2.7
import num2word_EN as s
text = open("C:\\Users\\eanaaks\\Desktop\\Python Practice Program\\Numbers.txt","r")
outfile = open("C:\\Users\\eanaaks\\Desktop\\Python Practice Program\\out.txt", "w")
for line in text:
line = line.rstrip()
num = int(line)
print line
x = s.to_card(num)
print (x)
outfile.write("%s\n"%(line));
outfile.close()
text.close()
請問你的文件是什麼樣子? –
你需要縮進'out_file.write()'否則你會只寫最後一行 –
你沒有做'text.close()',看看這個例子:http://stackoverflow.com/問題/ 4617034/how-can-i-open-multiple-files-using-open-in-python這使得它更容易編寫錯誤免費。我也不會在for循環中導入某些東西。 – martijnn2008