Scope objects

Robert Dailey rcdailey at gmail.com
Fri Jun 5 21:56:52 EDT 2009


Is it possible to create an object in Python that will clean itself up
at function exit? I realize destruction of objects may not occur
immediately and can be garbage collected, but this functionality would
still be great to have. Consider the following function:

def do_stuff():
    foo = scope_object()
    # Do stuff...
    foo.Cleanup()

It would be nice to avoid the explicit "Cleanup()" call above, and
have 'foo' just act as if it has a C++ destructor and evoke some
method at the exit point of a function.



More information about the Python-list mailing list