private

Hans Nowak wurmy at earthlink.net
Sat Jun 29 19:33:49 EDT 2002


Rhymes wrote:
> Is there any possibility to build up a _real_ private attribute?
> Such as C++ private data members...
> I know that with double-underscore prefix (and the name mangling related)
> I can " hide " data members but I think it's not a so crafty trick...
> Is there any PEP about it? Will Guido insert a private keyword
> in a future release of Python ?

IMHO, the lack of "real" private members is a feature.

You might want to look at 2.2's properties. However, using them adds quite a 
bit of extra code, and soon you'll be writing ugly C++ or Java-like code with a 
getter and setter for every attribute. A high price to pay for paranoia... ;-)

There are cases where some control over attributes is useful, but there are 
other ways to solve that...

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/




More information about the Python-list mailing list