importing a method

Flavio fccoelho at
Mon Nov 28 12:44:00 CET 2005

If you read my original post, I had no intention of atributing the
user's method to the class, but to the instance.

Anyway I figure it out myself, and its quite a Pythonic solution:
>>> class Foo:

>>> a=Foo()

>>> def p(parent):
            print 'Hi, %s!'

>>> a.met=p

>>> a.met(a)
Hi, John!

This works the same way an object's built-in method would work, since
all methods receive a reference to the parent object through the
required argument "self".

class Foo:
   def met(self):
       print self

Thanks for all the replies, they helped to catalize my own thoughts!


More information about the Python-list mailing list