What's the best way to iniatilize a function

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Mon May 28 08:57:14 EDT 2007


On Mon, 28 May 2007 11:01:26 +0200, Gregor Horvath wrote:

> Jack schrieb:
> 
>> I didn't call del explicitly. I'm expecting Python to call it when
>> the program exits. I put a logging line in __del__() but I never
>> see that line printed. It seems that __del__() is not being called
>> even when the program exits. Any idea why?
>> 
>> 
> 
> http://effbot.org/pyfaq/my-class-defines-del-but-it-is-not-called-when-i-delete-the-object.htm
> 
> better solutions:
> 
> http://docs.python.org/ref/try.html
> http://docs.python.org/whatsnew/pep-343.html


They might be better solutions, but not for the Original Poster's problem. 

The O.P. has a library that has to hang around for long time, not just a
call or two, and then needs to be closed. 

try...except and with define *blocks of code*, not long-lasting libraries
with data, functions, etc. Maybe you could shoe-horn the O.P.'s problem
into a with block, but the result would surely be ugly and fragile.



-- 
Steven.




More information about the Python-list mailing list