Need help with "global" variables

Pugsley europax at home.com
Sat Jul 14 23:00:46 EDT 2001


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