generating method names 'dynamically'

bruno at modulix onurb at xiludom.gro
Fri Jan 27 10:26:02 CET 2006

Daniel Nogradi wrote:
> Is it possible to have method names of a class generated somehow dynamically?

>>> class Dummy(object):
...   pass
>>> def mymethod(self, *args, **kw):
...   pass
>>> setattr(Dummy, 'a_dynamically_generated_method_name', mymethod)
>>> Dummy.a_dynamically_generated_method_name
<unbound method Dummy.mymethod>

bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"

More information about the Python-list mailing list