Skip to content

Instantly share code, notes, and snippets.

@arsho
Created May 19, 2017 03:38
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 arsho/98db85456f57b92639faedcf7aff045a to your computer and use it in GitHub Desktop.
Save arsho/98db85456f57b92639faedcf7aff045a to your computer and use it in GitHub Desktop.
Private variable tricks is not working in Python 3.6
class A:
def __init__(self):
self.__var1 = 123
self.__dict__ = {} # override to prevent peeking
# then randomize the pattern of private variable
# ie "_classname__variablename" is too obvious
def printVar1(self):
print(self.__var1)
x = A()
x.printVar1() #AttributeError: 'A' object has no attribute '_A__var1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment