Re: What's the best way to iniatilize a function

2007-05-28 Thread Laurent Pointal
Jack wrote: >>> 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 >

Re: What's the best way to iniatilize a function

2007-05-28 Thread Steven D'Aprano
On Sun, 27 May 2007 23:20:49 -0700, Jack wrote: > 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 m

Re: What's the best way to iniatilize a function

2007-05-28 Thread Steven D'Aprano
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

Re: What's the best way to iniatilize a function

2007-05-28 Thread Gregor Horvath
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-

Re: What's the best way to iniatilize a function

2007-05-27 Thread Jack
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 f

Re: What's the best way to iniatilize a function

2007-05-27 Thread Steven D'Aprano
On Sun, 27 May 2007 10:51:46 -0700, Jack wrote: > I have a set of functions to wrap a library. For example, > > mylib_init() > mylib_func() > mylib_exit() > > or > > handle = mylib_init() > mylib_func(handle) > mylib_exit(handle) > > In order to call mylib_func(), mylib_init() has to be called

What's the best way to iniatilize a function

2007-05-27 Thread Jack
I have a set of functions to wrap a library. For example, mylib_init() mylib_func() mylib_exit() or handle = mylib_init() mylib_func(handle) mylib_exit(handle) In order to call mylib_func(), mylib_init() has to be called once. When it's done, or when program exits, mylib_exit() should be called