在Python中确实没有任何真正的“私有”属性或方法。您可以做的一件事就是简单地覆盖子类中不需要的方法,并引发一个异常:
>>> class Foo( object ):... def foo( self ):... print 'FOO!'... >>> class Bar( Foo ):... def foo( self ):... raise AttributeError( "'Bar' object has no attribute 'foo'" )... >>> b = Bar()>>> b.foo()Traceback (most recent call last): File "<interactive input>", line 1, in <module> File "<interactive input>", line 3, in fooAttributeError: 'Bar' object has no attribute 'foo'



