Protecting instance variables

Diez B. Roggisch deets at nospam.web.de
Fri Jul 18 06:28:19 EDT 2008


Nikolaus Rath schrieb:
> Hello,
> 
> 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...

http://groups.google.com/group/comp.lang.python/browse_thread/thread/188467d724b48b32/

To directly answer your question: that's what the __ (double underscore) 
name mangling is for.

Diez



More information about the Python-list mailing list