How to give a global variable to a function which is in a module?

Kurda Yon kurdayon at yahoo.com
Wed Oct 1 11:44:21 EDT 2008


Hi,

I would like to declare a global variable, which is seen to a
particular function. If I do as the following it works:

x = 1
def test():
  global x
  print x
  return 1

However, it does not helps since my function is in a separate file. In
other words I have a main program which has the following structure:

from test import test
x = 1
y = test()

and I have a test.py file which contains the "test" function:
def test():
  global x
  print x
  return 1

In this case the test does not see the global variable x. How can I
make the x to be visible?

Thank you.



More information about the Python-list mailing list