[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] A question about callback functions




On Aug 29, 2005, at 6:24 AM, Guillaume Proux wrote:

Have a look at this interactive session!

C:\Documents and Settings\guillaume>\python23\python
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class FirstClass:
... def __init__(self,value):
... self.val=value
... def show(self):
... print "FirstClass",self.val
...
>>> class SecondClass:
... def __init__(self,value):
... self.val=value
... def show(self):
... print "SecondClass",self.val
...
>>> classname = "SecondClass"
>>> myclass = eval(classname)
>>> instance = apply(myclass,(3,))

apply is deprecated and slower than the alternative, don't use it. This is better written as myclass(3) or at worst myclass(*(3,))


-bob