Python 2.6 Global Variables

Aahz aahz at pythoncraft.com
Fri Oct 30 19:37:56 EDT 2009


In article <888b5e8f-1be5-4040-bc7a-45c2e16954fc at d9g2000prh.googlegroups.com>,
AK Eric  <warpcat at sbcglobal.net> wrote:
>>
>> 2/ in Python, "global" really means "module-level" - there's nothing
>> like a "true" global namespace.
>
>Isn't that __main__?
>
>import __main__
>__main__.foo = "asdfasdf"
>
>print foo
># asdfasdf

Actually, you're almost right, but it's an even WORSE idea than you
thought:

import __builtin__
__builtin__.foo = 'bar'

Kids, do *NOT* do this at home!  The reasons why are left as an exercise
for the reader.  ;-)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"You could make Eskimos emigrate to the Sahara by vigorously arguing --
at hundreds of screens' length -- for the wonder, beauty, and utility of
snow."  --PNH to rb in r.a.sf.f



More information about the Python-list mailing list