各位大家好,我有一个程式码希望能将 XXXX 这四个数据由 0000 依序增加到 ZZZZ
因此写了一段程式码如下:
my_list =["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
Output_File = open('OUTPUT.TXT', 'w')
for i in range(30,36):
for j in range(30,36):
for k in range(30,36):
for l in range(30,36):
print my_list[i]+my_list[j]+my_list[k]+my_list[l]
Output_File.write(my_list[i]+my_list[j]+my_list[k]+my_list[l]+"\n")
Output_File.Close
此时,print到萤幕上的结果可以顺利的跑到ZZZZ
然而输入到档案内的结果却只到:
XYYV
XYYW
X
(以下空白)
此外,当我要关闭Output_File时,他显示
Traceback (most recent call last):
File "X:/XXXX/XXXX/XXXX/XXX.py", line 9, in <module>
Output_File.Close
AttributeError: 'file' object has no attribute 'Close'
想请问是不是我程式码上有任何错误?
虽然以前写Fortran时也曾遇到数据累积量不足时不会写到档案内的状况
但是Fortran会在程式结束时将所有数据写进去,不会像Python这样断掉
感恩 :)