try: finally: question
Nick Smallbone
nick at nick8325.freeserve.co.uk
Fri Jul 9 08:36:35 EDT 2004
"djw" <donald.welch at hp.com> wrote in message
news:40ec429e at usenet01.boi.hp.com...
> Peter Hansen wrote:
>
> > djw wrote:
> >
> >> Peter Hansen wrote:
> >>>Hmm... Also, I think it really *is* unusual (as in, "not usual"
> >>>meaning not really common) to nest try blocks.
> >>
> >> I am suprised that what I am trying to accomplish is unusual.
Basically,
> >> I want to acquire some resource/object (that requires cleanup).
> >
> > It *is* unusual, in the way I mean, because relatively little code
> > is involved with resource cleanup when it's required (in Python,
> > anyway), and relatively little resource cleanup is required when
> > programming, in general.
>
> I would agree (with regards to straight Python), but I disagree when you
> include I/O. The I/O I am interacting with requires cleanup. Simply
> allowing the device object I created to go out of scope and be
> automatically cleaned up does not cause the I/O to be cleaned up properly.
>
Why don't you define __del__() in the object so it can do its own cleanup?
Apologies if I've missed something important.
Nick
More information about the Python-list
mailing list