Newbie asks about static variables...

Tim Peters tim_one at email.msn.com
Sat May 8 03:35:02 EDT 1999


[William Tanksley, discovers that _eggs can be imported explicitly from
 module spam, as in spam._eggs, while "from spam import *" doesn't leave
 _eggs on anyone's face]

> ...
> This seems to me rather inconsistent behavior; is there a reason why
> this is so?

[Moshe Zadka]
> Python was not designed (I think) for thieves and murderers, unlike C++.

That's right.  Python was designed for *nice* people!  Part of being nice is
leaving strangers' private parts alone, and just because it's *nice* to
leave them alone -- unless, of course, you just can't help yourself.
Coincidence that _ and __ are orthographically both phallic and flaccid?  I
think not.  They're the nice forms of what a less civilized language would
spell | or (God forbid) ||.

> It never did (and, Guido willing, never will) support True Data
> Hiding(TM) or any such nonsense:

Oh, it did at one time.  The only keyword ever *removed* from the language
is "access", which used to support a pile of serious visibility
restrictions.  It was mostly contributed code, uglified the implementation
rather horridly, and Guido never liked it.  I'm not sure it was even
advertised, but the code was there for several years.

> the leading underscore is no more then a hint, and Python has some
> miniscule support for it in the implementation, by not importing it
> into current name-space. If someone will want to hack your code, he'll
> manage (even in C++, maybe not in extra-police-like languages like
> Eiffel).. But that's fine -- your job is only to warn him what he is
> doing is dangerous.

Back when the easily-circumvented "__" convention for mangling class-pvt
names was invented, Guido was provoked into revealing the true model for
Python's data-hiding philosophy:

[GvR, circa 1996]
> It's called "advisory locking."  It was pioneered for bike locks in
> Amsterdam :-)

not-to-be-mistaken-for-advisory-bombing-cuz-that's-not-nice-ly y'rs  - tim






More information about the Python-list mailing list