Skip to content

Instantly share code, notes, and snippets.

@wjwwood
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save wjwwood/b3f4d3a11dc7d767a90b to your computer and use it in GitHub Desktop.

Select an option

Save wjwwood/b3f4d3a11dc7d767a90b to your computer and use it in GitHub Desktop.
>>> class A(object):
... def __init__(self):
... self.__foo = 'bar'
... @property
... def foo(self):
... return self.__foo
...
>>> a = A()
>>> a.foo
'bar'
>>> a.foo = 'baz'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
>>> a._A__foo = 'baz'
>>> a.foo
'baz'
>>> a.__foo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute '__foo'
>>> a._A__foo
'baz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment