ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
question on garbage collection for python
by winexpert other posts by this author
Jun 1 2004 2:16AM messages near this date
Python for AI: OWL and CLIPS anyone? | question on garbage collection for python
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/
Thread:
winexpert
tjreedy
della

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved