Revisions
-
public revised this gist
Mar 13, 2013 . 1 changed file with 12 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,31 +1,27 @@ 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>,) """ -
DRMacIver revised this gist
Mar 13, 2013 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,10 +19,13 @@ def print1(*args): Bar().print2() Bar().print3() p = Bar().print3 p() """ Prints: (<__main__.Bar instance at 0x7f109c35ecf8>,) (<__main__.Printer instance at 0x7f109c35ecb0>,) (<__main__.Bar instance at 0x7f0b32bd7dd0>,) (<__main__.Bar instance at 0x7f379f67ddd0>,) """ -
DRMacIver created this gist
Mar 13, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ # 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>,) """