Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41418 > unrolled thread

Re: "eval vs operator.methodcaller" - which is better?

Started byChris Angelico <rosuav@gmail.com>
First post2013-03-19 01:03 +1100
Last post2013-03-19 01:03 +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.


Contents

  Re: "eval vs operator.methodcaller" - which is better? Chris Angelico <rosuav@gmail.com> - 2013-03-19 01:03 +1100

#41418 — Re: "eval vs operator.methodcaller" - which is better?

FromChris Angelico <rosuav@gmail.com>
Date2013-03-19 01:03 +1100
SubjectRe: "eval vs operator.methodcaller" - which is better?
Message-ID<mailman.3448.1363615385.2939.python-list@python.org>
On Tue, Mar 19, 2013 at 12:58 AM, Laxmikant Chitare
<laxmikant.general@gmail.com> wrote:
> Aha, that was smart Chris. Thank you.
>
> But this raises another question in my mind. What is the use case for
> operator.methodcaller ?

Most of the operator module is functional versions of what can be done
elsewhere with operators. They're not generally needed unless you
specifically need a function, such as for a map() call:

>>> a=[1,2,3,4,5]
>>> b=[50,40,30,20,10]
>>> list(map(operator.add,a,b))
[51, 42, 33, 24, 15]

(The list() call is unnecessary in Python 2, but means this will also
work in Python 3.)

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web