What's the best way to iniatilize a function

Jack nospam at invalid.com
Mon May 28 02:20:49 EDT 2007


Thanks Steven, for the reply. Very helpful. I've got a lot to learn in 
Python :)

Some questions:

> (1) Python can automatically free most data structures and close open
> files, but if your needs are more sophisticated, this approach may not be
> suitable.

Since it's a wrapper of a DLL or .so file, I actually need to call 
mylib_exit()
to do whatever cleanup the library needs to do.

>> 2. what's the right way to call mylib_exit()? I put it in __del__(self)
>> but it is not being called in my simple test.
>
> instance.__del__ is only called when there are no references to the
> instance.

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?





More information about the Python-list mailing list