Created
March 28, 2012 13:47
-
-
Save almet/2226320 to your computer and use it in GitHub Desktop.
Python methods and functools
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
# This doesn't work (self isn't passed when calling obj.bar or obj.baz | |
class MyClass(object): | |
def foo(self, foo=None): | |
# do something with foo | |
bar = functools.partial(foo="bar") | |
baz = functools.partial(foo="baz") | |
# This works | |
class MyClass(object): | |
def __init__(self): | |
self.bar = functools.partial(foo="bar") | |
self.baz = functools.partial(foo="baz") | |
def foo(self, foo=None): | |
# do something with foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment