Skip to content

Instantly share code, notes, and snippets.

@Jim-Holmstroem
Created August 27, 2012 09:40
Show Gist options
  • Save Jim-Holmstroem/3486982 to your computer and use it in GitHub Desktop.
Save Jim-Holmstroem/3486982 to your computer and use it in GitHub Desktop.
Map member functions in python
import operator as op
class A:
def test(self):
return "self.test()"
def test2(self,arg):
return "self.test2({arg})".format(arg=arg)
alist = map(lambda i: A(), range(10))
ans = map(op.methodcaller('test'), alist)
#can also be used to (rarely) simply things
op.methodcaller('test')(A())
#also works with arguments
op.methodcaller('test2','argument')(A())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment