binding a method to an instance?

Steven D. Arnold stevena at neosynapse.net
Tue May 28 03:38:01 EDT 2002


Hi,

I'm trying to bind a method to an instance like this:

class foo:

    def __init__( self ):
        def abc( self ):
            print "hello"
        self.bar = abc

i = foo()
i.bar()

Unfortunately, when I run the last line, I get:

Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: abc() takes exactly 1 argument (0 given)

Apparently `abc' looks like a regular function and not a bound method.
How can I make it appear as a bound method in my instance?

-------------------------------------------------------------- 
Steven D. Arnold                        stevena at neosynapse.net
AIM: abraxan                       MSN: neosynapse at hotmail.com







More information about the Python-list mailing list