1
如何寫入函數內的全局文件?Python全局文件
實施例:
output_file=open("output_file_name.txt", "w")
def write_to_file:
global output_file
output_file.write('something')
write_to_file()
output_file.close()
上面的代碼不工作。它說「ValueError:關閉文件上的I/O操作」 有什麼想法?
該代碼不會給出該錯誤。 – 2012-01-30 06:44:12
parens on def? – wim 2012-01-30 06:51:43
適用於Python 2.5,Python 2.7,Python 3.2 – 2012-01-30 09:55:45