importing a method

Flavio fccoelho at gmail.com
Mon Nov 28 06:54:21 EST 2005


There only one puzzle left to solve:

altough the solution I proposed works, this variant has problems:

>>> class Foo:
            name='John'

>>> a=Foo()
>>> def p():
            print 'Hi, %s!'%self.name
>>> a.met=p
>>> a.met.self = a
>>>a.met()
NameError: global name 'self' is not defined

This error is paradoxical since:

>>> a.met.self
<__main__.Foo instance at 0x405ed2ec>

Can anyone explain this?




More information about the Python-list mailing list