Here's an example (found it here):
- Code: Select all
x = 0
def change():
"""changing x: need global"""
global x
print 'adding 1'
x += 1
def show():
"""not changing x: no global needed, if global x exist in context"""
print 'show:', x
print x
show()
change()
show()
print x
When you put this in a file called "global.py" and run it in the terminal, it will give this output:
- Code: Select all
$ python global.py
0
show: 0
adding 1
show: 1
1
But when I create an Action Group that fires this python script, I get this error in the Event Log window:
- Code: Select all
Action Group Global Test
Script Error global.py: global name 'x' is not defined
Script Error Exception Traceback (most recent call shown last):
global.py, line 14, at top level
global.py, line 11, in show
NameError: global name 'x' is not defined
Is this a bug or a feature?