Searching equivalent to C++ RAII or deterministic destructors

Ulrich Eckhardt eckhardt at satorlaser.com
Thu Jul 2 06:12:19 EDT 2009


Bearophile wrote:
> Ulrich Eckhardt:
>> a way to automatically release the resource, something
>> which I would do in the destructor in C++.
> 
> Is this helpful?
> http://effbot.org/pyref/with.htm

Yes, it aims in the same direction. However, I'm not sure this applies to my
case. The point is that the resource handle is not just used locally in a
restricted scope but it is allocated and stored. The 'with' is something
that makes sense in the context of mutex locking, where you have a
well-defined critical section. What I need is something similar to open(),
which returs a file. When the last reference to that object goes out of
scope, the underlying file object is closed.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list