Need help with "global" variables
Nick Perkins
nperkins7 at home.com
Sat Jul 14 23:48:24 EDT 2001
Your modules are going to have to import the globals. You could put them
all in a separate file, call it "my_globals.py", and then in each file
(including the 'main' file), you would have:
from my_globals import *
"Pugsley" <europax at home.com> wrote in message
news:yH747.348232$p33.7087093 at news1.sttls1.wa.home.com...
> I'm converting a number crunching program from C to Numeric Python, and
> I'm really getting stuck on how to deal with global variables.
>
> For example, there are about 30 variables that are defined in the main
> program that I want to be global and available in the functions in the
> modules. (the modules are seperate files that I import). A simple
> example would be:
>
> def foo(arg1, arg2):
>
> global bar1, bar2, bar3, etc.
>
> result= bar1+bar2+bar3+ arg1+arg2
>
> return result
>
>
>
> But all I get are errors stating that the global variables have not been
> defined. This behavior seems to run counter to what is implied in some
> books that I've been reading.
>
> What am I doing wrong? Thanks, Rob.
More information about the Python-list
mailing list