derived / base class name conflicts
bruno at modulix
onurb at xiludom.gro
Fri Nov 11 11:20:36 CET 2005
christopherlmarshall at yahoo.com wrote:
> So putting two underscores in front of an instance variable (or any
> identifier used inside the scope of a class statement) invokes a name
> mangling mechanism
> Is it commonplace to use underscores
I assume you mean double underscore...
> when defining derived class
> instance variables,
> or is this considered against the grain of python?
I don't know if it's 'commonplace', but that's something I only do when
I absolutely want to protect a given attribute of a base class from
being accidentally overriden by a derived class. Else I use the usual
convention ('_name' => implementation, 'name' => API), and assume users
of my code will read the documentation (or the source FWIW) before
subclassing. Note that since 'users of my code' are mostly my coworkers
and I, this is a quite sensible assumption !-)
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list