Last active
February 20, 2016 14:31
-
-
Save tanishiking/d3e475e3abe511878c7d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hoge: | |
def __init__(self): | |
self.a = 1 | |
def __get_a(self): | |
return self.a | |
def geta(self): | |
# 普通に __get_a()にアクセスできる | |
a = self.__get_a() | |
return a | |
if __name__ == '__main__': | |
h = hoge() | |
print(h.geta()) # print 1 | |
# h.__get_a() は Attribute Error になるが... | |
print(h._hoge__get_a()) # print 1 !!!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://docs.python.jp/3/tutorial/classes.html#private-variables