"Private" attributes - a possible idea (maybe PEP-worthy).
Michal Wallace
sabren at manifestation.com
Thu Jan 31 13:38:01 EST 2002
On Thu, 31 Jan 2002, Delaney, Timothy wrote:
> > From: Skip Montanaro [mailto:skip at pobox.com]
> > Tim> a.Klass -> _1__attr1 and _1__attr2
> > Tim> b.Klass -> _2__attr1 and _2__attr2
> >
> > This would be unworkable. Private attributes couldn't be pickled.
>
> Damn - knew there had to be *something* big against it.
>
>
> However, I can't help but feel that there must be *some*
> way to enforce that a "private" variable won't be
> accidentally used by a subclass.
But that's exactly what the magical __whatever notation is
for int he first place! :)
The "__" prefix (when the variable does not also end in "__")
is magically transformed into a string containing the
owner's classname. So, if a subclass uses __abc, it's a
different string than the parent's __abc.
If you get the magic string, you CAN override the parent
variable, but you have to go out of your way to explicitly
do that.
Cheers,
- Michal http://www.sabren.net/ sabren at manifestation.com
------------------------------------------------------------
Give your ideas the perfect home: http://www.cornerhost.com/
cvs - weblogs - php - linux shell - perl/python/cgi - java
------------------------------------------------------------
More information about the Python-list
mailing list