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 456x.printVar() => A.printVar(x)A.printVar()xA.printVar()
TA贡献1854条经验 获得超8个赞
添加回答
举报
