Skip to content

Instantly share code, notes, and snippets.

@ojii
Created February 4, 2019 05:47
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 ojii/c25f31db54c1d20564d1c4cab938582d to your computer and use it in GitHub Desktop.
Save ojii/c25f31db54c1d20564d1c4cab938582d to your computer and use it in GitHub Desktop.
In [1]: class Foo:
...: def __init__(self):
...: exec("self.__bar = 'hello'")
...: def bar(self):
...: print(self.__bar)
...:
In [2]: foo = Foo()
In [3]: foo.__bar
Out[3]: 'hello'
In [4]: foo.bar()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-8b3beb1ccf05> in <module>
----> 1 foo.bar()
<ipython-input-1-3b5b82ebc0e7> in bar(self)
3 exec("self.__bar = 'hello'")
4 def bar(self):
----> 5 print(self.__bar)
6
AttributeError: 'Foo' object has no attribute '_Foo__bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment