__del__ and saving/restoring dc
Robin Dunn
robin at alldunn.com
Thu Sep 20 10:07:15 PDT 2007
Chris Mellon wrote:
> On 9/20/07, Robin Dunn <robin at alldunn.com> wrote:
>> David Montgomery wrote:
>>
>>> But I was under the impression that one shouldn't
>>> rely on __del__ for this kind of thing in python, because
>>> you don't really know when __del__ is going to be
>>> called.
>> At least in CPython it will be called as soon reference count goes to
>> zero. So if there is only one reference __del__ will be called as soon
>> as it goes out of scope, just like the destructor of a C++ object on the
>> stack.
>>
>
> In Python 2.5, you can use the with statment with objects that support
> the context manager protocol. This is an explicit implementation of
> RAII, and is better in that it gives you a guarantee of the behavior
> as well as letting you know if you exited normally or due to an
> exception.
>
> See http://docs.python.org/whatsnew/pep-343.html for details. They are
> very easy to write, and I encourage people like Andrea to implement
> the context manager interface for these sort of objects.
wxPython needs to support Python 2.4 for a while yet, and I'm still
making binaries for Python 2.3 as well, so we can't have any 2.5
specific code in the standard library currently. (And Andrea's
LabelBook is one that I think he is going to make available in the
standard library.)
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wx-users
mailing list