Skip to content

Instantly share code, notes, and snippets.

@Kniyl
Last active April 15, 2016 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kniyl/58d145e3ec97b245b27db94d80074e81 to your computer and use it in GitHub Desktop.
Save Kniyl/58d145e3ec97b245b27db94d80074e81 to your computer and use it in GitHub Desktop.
class A1(object):
def __init__(self, **kwargs):
for k,v in kwargs.items():
setattr(self, k, v)
class A2(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
class B1(A1):
def __init__(self):
super(B1, self).__init__(test=1)
@property
def test(self):
return 42
class B2(A2):
def __init__(self):
super(B2, self).__init__(test=1)
@property
def test(self):
return 42
test = B2()
print test.test # outputs 42
test = B1() # AttributeError: can't set attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment