Skip to content

Instantly share code, notes, and snippets.

@public
Forked from DRMacIver/method_invocation.py
Created March 13, 2013 17:27
Show Gist options
  • Save public/5154306 to your computer and use it in GitHub Desktop.
Save public/5154306 to your computer and use it in GitHub Desktop.
class Printer(object):
def __call__(*args):
print 'call', args
def __get__(*args):
print 'get', args
return args[0]
def print_stuff(*args):
print(args)
class Bar(object):
def print1(*args):
print(args)
print2 = Printer()
print3 = print_stuff
Bar().print1()
Bar().print2()
Bar().print3()
"""
Prints:
(<__main__.Bar object at 0x10f3f6b10>,)
get (<__main__.Printer object at 0x10f3f6ad0>, <__main__.Bar object at 0x10f3f6b10>, <class '__main__.Bar'>)
call (<__main__.Printer object at 0x10f3f6ad0>,)
(<__main__.Bar object at 0x10f3f6b90>,)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment