call method by name?
Brian Quinlan
brian at sweetapp.com
Thu Jan 24 19:58:54 EST 2002
More information about the Python-list mailing list
Thu Jan 24 19:58:54 EST 2002
- Previous message (by thread): Patch with mem leak fixes for Python 1.5.2
- Next message (by thread): call method by name?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Chris Liechti wrote: > > How to say this in Python? > > > > method_name = 'method1' > > a. at method_name() > > apply(a, method_name) This won't work. apply expects a callable as its first argument and a parameter list as its second argument. If you wanted to be verbose, you could write it as: apply(getattr(a, method_name),()) But the apply is really redundant: getattr(a, method_name)() Cheers, Brian
- Previous message (by thread): Patch with mem leak fixes for Python 1.5.2
- Next message (by thread): call method by name?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list