[Tutor] Global scope
Pete Versteegen
pversteegen@gcnetmail.net
Sat Feb 1 09:37:01 2003
Listers,
I am confused about global variables. I have a C/C++ program with a large
number of functions, and a block of global variables (I know its best to
pass references to functions, but the pass-through list would often be long,
and its hence much easier to keep track of the definitions in a single
block) that I'm converting to python. I am translating the functions into
corresponding modules. Functions call functions, which in turn call othr
functions, etc. How do I declare some variables, including lists and
dictionaries, that are used in these lower functions to be globals,
accessible by all functions?
I used a statement such as: global case_number in a function, and declare
it case_number = 0 in the main module, but I get:
NameError: global name 'case_number' is not defined
BTW, I asked some time ago about formatting a la Fortran. At the link below
is a module that does all of that.
http://starship.python.net/crew/hinsen/part2.html
Thanks!
Pete Versteegen
pversteegen@gcnetmail.net
__________________________