Namespace question...

raptor_99_uk at my-deja.com raptor_99_uk at my-deja.com
Wed Nov 10 16:36:36 CET 1999


In article <7vqgib$l8v$1 at nnrp1.deja.com>,
  oofoe at my-deja.com wrote:
> Hi!
>
> 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.
>
> I have something like this:
>
> module file foo.py:
> ------------------------------
> Version = '$Id$'
>
> def bar():
>    print "Version is: ", __main__.Version
>
> main program:
> ------------------------------
> Version = '$Id$'
>
> import foo
>
> foo.bar()
>
> -------------------------------
>
> I'd certainly appreciate any pointers. The
namespace stuff seems to get
> a little hazy around issues like this.
>
> Thanks!
>
> Jos'h
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

just declare Version to be global inside bar() as
follows:

def bar():
    global Version
    print "Version is: ", Version


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list