variable naming query
Neil Cerutti
horpner at yahoo.com
Fri Jul 13 10:07:43 EDT 2007
On 2007-07-12, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
>> self.__myvariable
>
> Indicates to the reader that the attribute '__myvariable' is
> not available by that name outside the object, and name
> mangling is automatically done to discourage its use from
> outside the object.
>From _Python Reference Manual (2.3.2) Reserved Classes of
Identifiers:
__*
Class-private names. Names in this category, when used
within the context of a class definition, are re-written to
use a mangled form to help avoid name clashes between
``private'' attributes of base and derived classes.
Further, from the _Python Tutorial (9.6) Private Variables_:
(Buglet: derivation of a class with the same name as the base
class makes use of private variables of the base class
possible.)
In other words, it's a misfeature that's best avoided.
--
Neil Cerutti
More information about the Python-list
mailing list