Adding methods to an object
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Thu Oct 13 09:16:53 EDT 2005
More information about the Python-list mailing list
Thu Oct 13 09:16:53 EDT 2005
- Previous message (by thread): Adding methods to an object
- Next message (by thread): Adding methods to an object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This isn't code of mine, it's probably from the cookbook, maybe with little changes: | def addMethod(object, method, name=None): | if name is None: name = method.func_name | class newclass(object.__class__): | pass | setattr(newclass, name, method) | object.__class__ = newclass name is the name for the new method, if it's None then the name of "method" is used. Bye, bearophile
- Previous message (by thread): Adding methods to an object
- Next message (by thread): Adding methods to an object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list