generating method names 'dynamically'

Farshid Lashkari lashkariNO at SPAMworldviz.com
Thu Jan 26 18:47:40 EST 2006


> Is it possible to have method names of a class generated somehow dynamically?

If you don't know the name of the method ahead of time, how do you write 
the code for it? Do you use some dummy name? If so, once you have the 
name determined then you could use setattr to set the method name. 
Here's a simple example:

class MyClass:
     def DummyMethodName(self): pass

setattr(MyClass,'NewMethodName',MyClass.DummyMethodName)

-Farshid



More information about the Python-list mailing list