A
Aaron Deskins
I'm trying to write program with a main.py and several functions
distributed in auxiliary *.py files. I've looked through the archives on
the 'global' keyword, but I'm still not sure how to get this right. I
want to be able to have some variables that can be accessed/changed by
many modules/functions.
Here's an example.
____________
main.py
____________
import change
n = 1
change.change_n()
print n
____________
change.py
____________
def change_n():
global n
n = 2
Running main.py gives this: 1. So n is not being changed when the
function is called. I've tried adding a 'import from main *' line to
change.py, but this only gives an error message.
Any ideas?
Thanks
distributed in auxiliary *.py files. I've looked through the archives on
the 'global' keyword, but I'm still not sure how to get this right. I
want to be able to have some variables that can be accessed/changed by
many modules/functions.
Here's an example.
____________
main.py
____________
import change
n = 1
change.change_n()
print n
____________
change.py
____________
def change_n():
global n
n = 2
Running main.py gives this: 1. So n is not being changed when the
function is called. I've tried adding a 'import from main *' line to
change.py, but this only gives an error message.
Any ideas?
Thanks