Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41413
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'args': 0.04; 'val': 0.07; 'conf': 0.09; '3.3,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:which': 0.16; 'wrote:': 0.17; 'variables': 0.17; 'file.': 0.20; 'import': 0.21; 'skip:_ 20': 0.22; 'example': 0.23; 'least': 0.25; 'header:In- Reply-To:1': 0.25; 'am,': 0.27; '2.6': 0.27; 'message- id:@mail.gmail.com': 0.27; 'print': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85.220': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'skip:m 40': 0.36; 'two': 0.37; 'received:209': 0.37; 'to:addr:python.org': 0.39; '2013': 0.84; 'subject:better': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=U+UJjgxuTtuk8YILupKIb/7Z8O5xdt8VcJd1ppAEbqE=; b=wbKAj6fQ7+hhgrUt/yFbkwaR4kRW429FV6ct0KvCC+zUPnQhoJizVvNfUxb8JET49f 2HdwSi7h53mkFYKdU/IBxfw3eLytu3UD2fVY0Bk3d3bpiPJW8SqlDdYbau5n3q7q0/p8 zLp3oevFJVt3erqxsrnf7LILBketx9ZuK++mv8FOPMxVoscmZ3Q/uHPksiqRPQGpGX2M gFbbFb6AGuW1BbtLiCPVcOQh8aQIMVrWyniMxHYRKU0HtUZWyTjohdx2/Vj4A+BPL9GE UEfdP4o+LirSrSsypw+RNMxiUvvMUHnwUGzAYRQ4ye4+oYolvyxncFbDDKLSVECC8AnB ObUw== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.37.109 with SMTP id x13mr17304646vdj.10.1363613950625; Mon, 18 Mar 2013 06:39:10 -0700 (PDT) |
| In-Reply-To | <CAFtnWG-8dndo6KYrmKvgsbiB5YkfBOgbPLrzHXauuOygvGbHtw@mail.gmail.com> |
| References | <CAFtnWG-8dndo6KYrmKvgsbiB5YkfBOgbPLrzHXauuOygvGbHtw@mail.gmail.com> |
| Date | Tue, 19 Mar 2013 00:39:10 +1100 |
| Subject | Re: "eval vs operator.methodcaller" - which is better? |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3442.1363613958.2939.python-list@python.org> (permalink) |
| Lines | 18 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363613958 news.xs4all.nl 6875 [2001:888:2000:d::a6]:59674 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41413 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: "eval vs operator.methodcaller" - which is better? Chris Angelico <rosuav@gmail.com> - 2013-03-19 00:39 +1100
csiph-web