Created
May 19, 2017 03:38
-
-
Save arsho/98db85456f57b92639faedcf7aff045a to your computer and use it in GitHub Desktop.
Private variable tricks is not working in Python 3.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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