Skip to content

Instantly share code, notes, and snippets.

@wyukawa
Created May 20, 2013 02:34
Show Gist options
  • Select an option

  • Save wyukawa/5610137 to your computer and use it in GitHub Desktop.

Select an option

Save wyukawa/5610137 to your computer and use it in GitHub Desktop.
python inherit instance variable
class A(object):
def __init__(self):
self.a = 1
def hoge(self):
if hasattr(self, "a"):
return self.a
else:
return 0
class B(A):
def __init__(self):
# self.a = 1
self.b = 2
if __name__ == '__main__':
b = B()
print b.hoge() # print 0. not 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment