[Python-Dev] Variable Scope

RN rohit.nadhani at tallysolutions.com
Mon Nov 17 04:22:05 EST 2003


I have a 2 Python scripts that contain the following lines:

test.py
-------
from testmod import *
a1 = 10
modfunc()

testmod.py
-----------
def modfunc():
    print a1

When I run test.py, it returns the following error:

  File "testmod.py", line 2, in modfunc
    print a1
NameError: global name 'a1' is not defined

My intent is to make a1 a global variable - so that I can access its value
in all functions of imported modules. What should I do?

Thanks in advance,

Rohit






More information about the Python-Dev mailing list