-
-
Save hryniuk/9d0451d3c502d3a5bd40aa3990747af3 to your computer and use it in GitHub Desktop.
Partial method application
This file contains hidden or 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 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