apply for objects

Bernhard Herzog herzog at online.de
Wed Jun 21 14:00:51 EDT 2000


Hahn S <shahn at kits.cs.vu.nl> writes:

> Ok, i have figured out how to use apply on methods. You just have to get
> the method from the class and use the im_func in the apply. The first
> argument must be the one which should be the self object.
> 
> Example:
> >>> class D:
> 	def start(self, hoi, daar=100):
> 		print self.aap
> 		print hoi
> 		print daar
> 
> 
> >>> d = D()
> >>> d.aap = 'Artis is leuk'
> >>> apply(D.start.im_func, (d, 'Hello World'))
> Artis is leuk
> Hello World
> 100

>>> apply(d.start, ('Hello World',))
Artis is leuk
Hello World
100

Works just as well. There's no need to mess around with im_func.

-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list