Created
August 27, 2012 09:40
-
-
Save Jim-Holmstroem/3486982 to your computer and use it in GitHub Desktop.
Map member functions in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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