Newbie asks about static variables...

Moshe Zadka moshez at math.huji.ac.il
Fri May 7 09:34:40 EDT 1999


On Thu, 6 May 1999, Martijn Faassen wrote:

> William Tanksley wrote:
<snipped some discussion about _ and __ in Python>

> However, my testing indicates that the '_' behavior wasn't as I thought
> it would be. A global variable _foo indeed isn't imported if you do a
> 'from module import *'. But it's perfectly possible to do 'import
> module; print module._foo', it turns out to my surprise! This seems to
> me rather inconsistent behavior; is there a reason why this is so?
> 
> Of-course-I-never-noticed-this-anyway-as-I-just-never-tried-before-ly

Python was not designed (I think) for thieves and murderers, unlike C++. 
It never did (and, Guido willing, never will) support True Data Hiding(TM)
or any such nonsense: 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.

so-Python-can-be-used-to-break-OO-police-laws-and-we-all-like-it-for-it-ly
y'rs, Z.

--
Moshe Zadka <mzadka at geocities.com>. 
QOTD: My own exit is more likely to be horizontal then perpendicular.






More information about the Python-list mailing list