--- Tavis Rudd <[EMAIL PROTECTED]> wrote:
> On September 10, 2002 01:14 pm, Tim Roberts wrote:
> > >> As a stylistic note: you should not generally
> use
> > >> double underscores as a lead-
> > >> in for your own variable names.  Those are
> reserved
> > >> for Python itself.
> > >
> > >I always thought double underscores was a method
> for
> > >making attributes and methods 'private' (actually
> > >'mangled' would be the right word since there
> isn't
> > >the 'security' that C++ provides).
> > >
> > >Can someone confirm either theory for us?
> >
> > *One* underscore marks an attribute or method as
> private.  Double
> > underscored names are reserved for Python.
> 
> No.  Single _ is a convention that means "Hey other
> programmer, this is
> private, don't use it!" The Python interpreter does
> nothing to enforce this.
> Double __ is a language feature that means "Hey
> Python, this is private. Hide
> it!"  It is enforced, sort of.
> 
> Tavis
> 

Correct. Upon further research...

__private_name

__restricted_name__

If you start and end with 2 underscores then you are
talking about a restricted name which is 'OK' to use
but python has the right to use the name in the
future, so it's a bad idea to say the least.

Here is how the mangling of double underscores works:

class Ham:
   __spam = None

> print dir(Ham())
['_Ham__spam', '__doc__', '__module__']

Notice how it puts the class name Ham before the
'private' attribute name? That is what is meant by
'mangling' since you can still access it by:

> print Ham()._Ham__spam
None

but 

> print Ham().__spam

gives you an error.

regards,
Ian Maurer

__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute


-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to