Why less emphasis on private data?
Thomas Ploch
Thomas.Ploch at gmx.net
Sun Jan 7 10:52:13 EST 2007
Paul Rubin schrieb:
> Thomas Ploch <Thomas.Ploch at gmx.net> writes:
>> Me neither, although I have to say that the '__' prefix comes pretty
>> close to being 'private' already. It depends on the definition of
>> private. For me, private means 'not accessible from outside the
>> module/class'.
>
> class A:
> __x = 3
>
> class B(A):
> __x = 4 # ok
>
> class C(B):
> __x = 5 # oops!
>
> Consider that the above three class definitions might be in separate
> files and you see how clumsy this gets.
I don't understand why this should be oops, even if they are in
different files.
>>> a = A()
>>> print a._A__x
3
>>> b = B()
>>> print b._B__x
4
>>> c = C()
>>> print c._C__x
5
>>> dir(c)
['_A__x', '_B__x', '_C__x', '__doc__', '__module__']
>>> print c._A__x
3
>>> print c._B__x
4
More information about the Python-list
mailing list