Scope actions

Will McGugan news at NOwillmcguganSPAM.com
Sat Oct 9 10:48:19 EDT 2004


Hi,

I often write small classes in C++ the use the side effects of scope. 
For example a CAutoLock class that locks a mutex in the constructor and 
releases it in the destructor. Is this something that is easily 
accomplished in Python? I'm guessing that using __init__ and __del__ 
would be roughly equivalent to this. But can can I be sure - with 
garbage collection - that __del__ is called immediately at the point of 
going out of scope?

Alternatively, should I give up this little idiom and use try / finally?


Thanks,

Will McGugan



More information about the Python-list mailing list