Skip to content

Instantly share code, notes, and snippets.

@gtt116
Created March 2, 2015 07:48
Show Gist options
  • Save gtt116/de2ec00cdcc07626ab50 to your computer and use it in GitHub Desktop.
Save gtt116/de2ec00cdcc07626ab50 to your computer and use it in GitHub Desktop.
python weird codes
"""
Why line 21 raise ??
"""
def error():
print 'foo'
class OK(object):
pass
class Hehe():
impl_ok = OK
impl_err = error
def __init__(self):
self.implement = self.__class__.impl_ok()
print self.implement
self.implement = self.__class__.impl_err()
print self.implement
he = Hehe()
@gtt116
Copy link
Author

gtt116 commented Mar 2, 2015

<__main__.OK object at 0x7f75bc03b750>
Traceback (most recent call last):
  File "a.py", line 26, in <module>
    he = Hehe()
  File "a.py", line 22, in __init__
    self.implement = self.__class__.impl_err()
TypeError: unbound method error() must be called with Hehe instance as first argument (got nothing instead)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment