假设有如下一个python类:
class Foo(object):
def __a(self):
print "Bet you can't see me..."
def bar(self):
self.__a()
而s是Securityp的一个实例,我们
s._Foo__a()
这种机制可以阻止继承类重新定义或者更改方法的实现,比如,定义一个Foo的派生类:
class Goo(Foo):
def __a(self):
print 'private method of Goo'
g = Goo()
g.bar()
"Bet you can't see me..."
self.__a()已自动变形为self._Foo__a(),Goo继承的bar()方法也是如此