Created
January 30, 2013 23:13
-
-
Save danielhfrank/4678236 to your computer and use it in GitHub Desktop.
Methods not defined within class don't pass self as first arg
This file contains 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
class X(object): | |
def __str__(self): | |
return 'x' | |
def my_print_arg(*args): | |
print args[0] | |
def print_arg(*args): | |
print args[0] | |
if __name__ == '__main__': | |
x = X() | |
x.y = print_arg | |
x.y('z') # prints 'z' | |
x.my_print_arg('z') # prints 'x' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment