0
我正在做一個數字列表生成器,我想打印輸出作爲一個.txt文件中的列表,但它總是隻打印變量的最終值。這裏是我的代碼:如何將for循環輸出打印到文本文件中?
zero = ["000000","00000","0000","000","00","0",""]
for x in xrange(0,999999):
with open("Output.txt", "w") as text_file:
text_file.write("011"+zero[len(str(x))] + str(x)+"70")
見http://stackoverflow.com/help/formatting – Barmar
...''011 {:06D} 70'.format(X)'... –