[Tutor] Global scope
Francois Granger
francois.granger@free.fr
Sat Feb 1 10:06:02 2003
At 09:36 -0500 01/02/2003, in message [Tutor] Global scope, Pete
Versteegen wrote:
>
>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
#! python
global case_number, other
case_number = 0
def myFunc():
global case_number
case_number += 1
Untested.
But if you have a lot of them, you will have a better time creating a
separate module for all these and import it or have a dict holding
all of them.
#! python
myvars = {'case_number': 0,
'other': 1
}
def myFunc(vars):
vars['case_number'] += 1
result = myFunc(myvars)
--
Recently using MacOSX.......