using 'global' across source files.
Bram Stolk
bram at sara.nl
Wed Jan 3 04:17:32 EST 2001
Mark Jackson wrote:
>
> Bram Stolk <bram at sara.nl> writes:
> > According to the manuals, it should simply be in the namespace
> > '__main__', but that doesnt work either.
>
> You're misreading the manuals. Can you tell us how you drew this
> conclusion? (Possibly the manuals could be clearer.)
Well, because in execframes.html, it can be read that:
"The main module for a script is always called __main__"
And because I can do:
dir(__builtins__)
I thought, why the heck doesn't dir(__main__) work?
I also tried dir(__mains__), dir(main), etc.
Now I know, (thx Remco) that I first have to map the string
__main__ to a module using sys.
This could be in the ref manual. I think it is not in
there currently.
Also, I had no idea that using a 'global val' cmd, creates
another copy of val, which I deduct from your comment:
"But the val that change_val changes is defined in funcs.py,
NOT prog.py"
I thought that python's 'global' acted like C's 'extern' cmd,
meaning, that 'global val' does NOT define/create 'val',
only refers to a val that exists somewhere else.
I don't know wether me thinking this is due to my poor
understanding, or the quality of the manuals, though.
Anyway, to clear things up: what I wanted to achieve is
pretty straightforward: I can use "global vars" that
reside outside a func body, but in the same module.
I wanted one step further: use "even more global vars"
that reside outside a func body, and even outside the
current module (read: sourcefile).
I can achieve this now, with the sys lookup of __main__.
(Provided ofcourse that __main__ is the module that
holds the req'd variable).
I thought that the subject line that I had chosen
"using 'global' across source files" summed up my
problem pretty accurate. But appearantly it did not ;-)
Bram
>
> --
> Mark Jackson - http://www.alumni.caltech.edu/~mjackson
> The power of accurate observation is frequently called
> cynicism by those who don't have it.
> - George Bernard Shaw
--
------------------------------------------------------------------------------
Bram Stolk, VR Specialist.
SARA Academic Computing Services Amsterdam, PO Box 94613, 1090 GP AMSTERDAM
email: bram at sara.nl Phone +31-20-5923059 Fax +31-20-6683167
"I heard if you play the NT-4.0-CD backwards, you get a satanic message."
"Thats nothing, if you play it forward, it installs NT-4.0"
------------------------------------------------------------------------------
More information about the Python-list
mailing list