Namespace question...

Aahz Maruch aahz at netcom.com
Wed Nov 10 22:02:24 EST 1999


In article <80c3e4$vpq$1 at nnrp1.deja.com>,  <raptor_99_uk at my-deja.com> wrote:
>In article <7vqgib$l8v$1 at nnrp1.deja.com>,
>  oofoe at my-deja.com wrote:
>>
>> How can you access the global namespace in python 1.5.1? I'd like to get
>> a version string which is declared in the main script file. However,
>> each module also has a version string which overrides the original one.
>> I tried to access it as __main__.Version, similarly to $main::Version in
>> Perl, which is what I'm more familiar with. Of course, it didn't work.
>
>just declare Version to be global inside bar() as
>follows:
>
>def bar():
>    global Version
>    print "Version is: ", Version

Your response is wrong: it works within a module, but not inside a
module that has been imported into another script.  Eric Jacobs gave a
correct response (import __main__), but in general it's a better idea to
pass information in (interface specified) rather than having a module
make assumptions about what kind of script will import it.
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>      http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6  (if you want to know, do some research)




More information about the Python-list mailing list