question on garbage collection for python

David Stockwell winexpert at hotmail.com
Tue Jun 1 15:16:00 CEST 2004


Hi,

Does Python leave things in an unknown state?

say I do this in my python code


someFile = open('somefile' , 'r')

data = someFile.read()

someFile = 3

At this point I would hope python would know to destruct the prior reference 
to someFile by unallocating the memory (under the hood) and closing the 
file.

The questions here are:
If in my code if I forget to close a file, when will the file be closed?  Is 
it when something goes out of scope?  Or will it close when the python 
session ends?

If I define a class of somesort, is there a way I can have a destructor 
method (like I would under C++ ?)

Thanks in advance,

David

-------
Tracfone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE 
download! http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/





More information about the Python-list mailing list