Need help with "global" variables/resolved

Pugsley europax at home.com
Sun Jul 15 19:06:17 EDT 2001


Thanks for the posts and emails.  Yes I now realize that Python modules
are not like linked C modules.  I took some advice from the ng archive
and put all of my globals into a dummy class.  I can then just pass the
name of the class to wherever I need it.   Rob.



In article <yH747.348232$p33.7087093 at news1.sttls1.wa.home.com>, "Pugsley"
<europax at home.com> wrote:

> 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