Protecting instance variables
Diez B. Roggisch
deets at nospam.web.de
Fri Jul 18 12:28:19 CEST 2008
Nikolaus Rath schrieb:
> I am really surprised that I am asking this question on the mailing
> list, but I really couldn't find it on python.org/doc.
> Why is there no proper way to protect an instance variable from access
> in derived classes?
> I can perfectly understand the philosophy behind not protecting them
> from access in external code ("protection by convention"), but isn't
> it a major design flaw that when designing a derived class I first
> have to study the base classes source code? Otherwise I may always
> accidentally overwrite an instance variable used by the base class...
Here we go again...
To directly answer your question: that's what the __ (double underscore)
name mangling is for.
More information about the Python-list