Skip to content

Instantly share code, notes, and snippets.

@almet
Created March 28, 2012 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almet/2226320 to your computer and use it in GitHub Desktop.
Save almet/2226320 to your computer and use it in GitHub Desktop.
Python methods and functools
# 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