Parrot-0.0.1

Robert Kern kernr at mail.ncifcrf.gov
Mon Sep 6 02:25:26 EDT 1999


On Mon, 06 Sep 1999 11:09:54 +1200, Greg Ewing <greg.ewing at compaq.com>
wrote:

>Emile van Sebille wrote:
>> 
>> Off topic and probably obvious, but, how would you plug a function into
>> an instance?
>>
>> Hoping-to-say-WOW-but-anticipating-a-slapped-forehead-ly yrs
>
>class Foo:
>
>  def f():
>    self.g()
>
>def h():
>  print "Wow! (slap)"
>
>x = Foo()
>x.g = h
>x.f()

Umm...  Add a self argument to f.

Also, if you have a function like the following:

def i(self):
    print 'doing something'

you can make it a method of the class, like so:

Foo.i = i
x.i()

>Greg

Robert Kern           |
----------------------|"In the fields of Hell where the grass grows high
This space            | Are the graves of dreams allowed to die."
intentionally         |           - Richard Harter
left blank.           |




More information about the Python-list mailing list