Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41413 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-03-19 00:39 +1100 |
| Last post | 2013-03-19 00:39 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: "eval vs operator.methodcaller" - which is better? Chris Angelico <rosuav@gmail.com> - 2013-03-19 00:39 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-03-19 00:39 +1100 |
| Subject | Re: "eval vs operator.methodcaller" - which is better? |
| Message-ID | <mailman.3442.1363613958.2939.python-list@python.org> |
On Tue, Mar 19, 2013 at 12:30 AM, Laxmikant Chitare
<laxmikant.general@gmail.com> wrote:
> moduleName = 'mymodule' #These two variables are read from conf file.
> methodName = 'mymethod'
>
> import operator
> myModule = __import__('mymodule')
> myMethod = operator.methodcaller('mymethod')
> val = myMethod(myModule)
> print val
Is there any reason not to do the obvious?
val = myModule.__getattribute__(methodName)(... args ...)
Works in 2.6 and 3.3, at least on the trivial example I tried.
ChrisA
Back to top | Article view | comp.lang.python
csiph-web