3 回答

TA贡献1856条经验 获得超17个赞
__
__foo
_
__foo
_bar
.

TA贡献1155条经验 获得超0个赞
class A: def __init__(self): self.__var = 123 def printVar(self): print self.__var
__var
>>>x = A() >>>x.__var # this will return error: "A has no attribute __var" >>>x.printVar() # this gives back 123
>>>x.__dict__ # this will show everything that is contained in object x # which in this case is something like {'_A__var' : 123} >>>x._A__var = 456 # you now know the masked name of private variables >>>x.printVar() # this gives back 456
x.printVar() => A.printVar(x)
A.printVar()
x
A.printVar()

TA贡献1854条经验 获得超8个赞
添加回答
举报