Skip to content

Instantly share code, notes, and snippets.

@hryniuk
Created March 29, 2017 09:52
Show Gist options
  • Save hryniuk/9d0451d3c502d3a5bd40aa3990747af3 to your computer and use it in GitHub Desktop.
Save hryniuk/9d0451d3c502d3a5bd40aa3990747af3 to your computer and use it in GitHub Desktop.
Partial method application
import functools
class B():
def __init__(self, n):
self.n = n
def __call__(self):
print(self.n)
class A():
def __init__(self, b):
self.b = b
def f(self):
self.b()
b1 = B(3)
b2 = B(5)
a1 = A(b1)
a2 = A(b2)
f1 = functools.partial(A.f, a1)
f1()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment