
1 Septembers Apr 26, 2015 |
2 oclock Apr 26, 2015 read()执行完就被gc,因为*open(from_file)*没有被引用 喜欢oneliner可以那么写 |
3 laoyuan OP @oclock 我感觉没有立刻回收呢,下面这三行print 地址都是相同的 from_file = 'sample.txt' print open(from_file) print open(from_file) indata = open(from_file).read() print open(from_file) |
4 Sylv Apr 27, 2015 via iPhone "Close is always necessary when dealing with files, it is not a good idea to leave open file handles all over the place. They will eventually be closed when the file object is garbage collected but you do not know when that will be and in the mean time you will be wasting system resources by holding to file handles you no longer need." |
6 ryanking8215 Apr 27, 2015 |
7 czy1996 May 25, 2015 @ryanking8215 请教一下,还是不太明白,笨办法学python里说这样写的话read()一旦运行就被关掉了。 |