无需关闭文件? [英] No need to close file?
本文介绍了无需关闭文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这种情况下我需要关闭文件吗?为什么或为什么不呢?
for line in file(''foo'',''r''):
print line
Do I need to close the file in this case? Why or why not?
for line in file(''foo'', ''r''):
print line
推荐答案
在这种情况下我需要关闭文件吗?为什么或为什么不呢?
Tfor line in file(''foo'',''r''):
T打印行
No.引用计数的魔力。
S
TDo I need to close the file in this case? Why or why not?
Tfor line in file(''foo'', ''r''):
T print line
No. The magic of reference counting.
S
T写道:
T wrote:
在这种情况下我是否需要关闭文件?为什么或为什么不呢?
for line in file(''foo'',''r''):
打印行
Do I need to close the file in this case? Why or why not?
for line in file(''foo'', ''r''):
print line
关闭Jython中的文件,但通常在CPython中没有必要。
再见,
bearophile >
T napisa3(a):
T napisa3(a):
在这种情况下我需要关闭文件吗?为什么或为什么不呢?
for line in file(''foo'',''r''):
打印行
Do I need to close the file in this case? Why or why not?
for line in file(''foo'', ''r''):
print line
不,如果你只是从文件中读取。
但是无论如何,关闭文件对象被认为是很好的做法很多
我找到的文件,无论你用它做什么。
-
Jarek Zgoda
http://jpa.berlios.de/
这篇关于无需关闭文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文