function attributes are like function objects

Scottie me at nospam.net
Wed Feb 7 00:23:29 EST 2001


The dictionary (a in your example) will force a reference to the function to
exist, thus preventing it from being collected.  An attribute evaporates
with
the object it is connected to.  The difference provides another reason to
use
an attribute to perform the legerdemain rather than some (probably global)
dictionary.

On a separate note, can't a function acces itself through an exception's
 traceback frame?  Something like:
    try:
        raise MyExcept
    except MyExcept:
        obtain info thru via sys.exc_info()

"Christian Tanzer" <tanzer at swing.co.at> wrote:
> "Fredrik Lundh" <fredrik at effbot.org> wrote:
> > advantages:
> > + works with pre-2.1 python
> > + requires one dictionary per class instead of one
> >  per method
> - requires one dictionary per type of method attribute.
- prevents funtions referenced from being garbage collected.

--
Scott David Daniels          Scott.Daniels at Acm.Org







More information about the Python-list mailing list