-1
如何让python在播放器尝试退出时自动关闭打开的文件?退出时自动关闭打开的文件?
这是我到目前为止有:
hai = open('hai.txt','a')
quit = 0
while quit == 0:
hai.write('SPAM')
hai.close()
如何让python在播放器尝试退出时自动关闭打开的文件?退出时自动关闭打开的文件?
这是我到目前为止有:
hai = open('hai.txt','a')
quit = 0
while quit == 0:
hai.write('SPAM')
hai.close()
使用
with open("file.txt","a") as f:
#Do things with f
在大多数情况下,即使不使用with语句,蟒蛇将采取的是你。 http://blog.lerner.co.il/dont-use-python-close-files-answer-depends/ –