[问题] 输出到档案时数据不完全

楼主: dogs1231992 (河豚)   2017-07-04 23:17:48
各位大家好,我有一个程式码希望能将 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这样断掉
感恩 :)
作者: doghib (lun)   2017-07-04 23:23:00
Output_File.close()
作者: dannypsnl (秦书)   2017-07-04 23:28:00
你的是大写欸,Close()楼上写close()啊,试试吧
作者: Django (Cython)   2017-07-05 01:45:00
最近好多大小写问题的XD
作者: Sunal (SSSSSSSSSSSSSSSSSSSSSSS)   2017-07-05 13:10:00
除了大小写 命名规则也建议统一.....

Links booklink

Contact Us: admin [ a t ] ucptt.com