Skip to content

Instantly share code, notes, and snippets.

@bmaland
Created January 9, 2011 18:59
Show Gist options
  • Save bmaland/771908 to your computer and use it in GitHub Desktop.
Save bmaland/771908 to your computer and use it in GitHub Desktop.
>>> class C(object):
... cattr = "hej"
... def __init__(self, name):
... self.cattr = name
...
>>> c = C("hi")
>>> d = C("hej")
>>> d.cattr
'hej'
>>> c.cattr
'hi'
>>> c.__dict__
{'cattr': 'hi'}
>>> C.cattr
'hej'
>>> class C(object):
... cattr = "Hej"
... def __init__(self, name):
... C.cattr = name
...
>>> c = C("hi")
>>> c.cattr
'hi'
>>> C.cattr
'hi'
>>> d = C("sap")
>>> c.cattr
'sap'
>>> d.cattr
'sap'
>>> c.__dict__
{}
>>> class C(object):
... def __init__(self):
... self._x = 1
... @property
... def x(self): return self._x
... @x.setter
... def x(self, val): self._x = val
...
>>> c = C()
>>> c.x
1
>>> c.x = 2
>>> c.x
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment