-
-
Save public/5154306 to your computer and use it in GitHub Desktop.
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
# Python method invocation is a strange beast | |
# Note difference between assigning a callable object that isn't a function | |
# and a callable object that is one | |
class Printer: | |
def __call__(*args): | |
print(args) | |
def print_stuff(*args): | |
print(args) | |
class Bar: | |
def print1(*args): | |
print(args) | |
print2 = Printer() | |
print3 = print_stuff | |
Bar().print1() | |
Bar().print2() | |
Bar().print3() | |
""" | |
Prints: | |
(<__main__.Bar instance at 0x7f109c35ecf8>,) | |
(<__main__.Printer instance at 0x7f109c35ecb0>,) | |
(<__main__.Bar instance at 0x7f0b32bd7dd0>,) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment