假設有如下一個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()方法也是如此