python - How to import a module of functions and pass variables between modules -
a file 'definitions.py' contains code:
def testing(a,b): global result count in range(a,b): result.append(0) print result
while file 'program.py' contains code:
from definitions import * result = [] testing(0,10) print result
the result of definitions.py expected list of zeros, while variable within program.py empty list despite results being defined global variable. how can made run function definitions.py pass resulting variable used within program.py?
global namespaces relative module. not shared between modules.
you return result
:
def testing(a,b): result = [] count in range(a,b): result.append(0) return result
and use this:
result = testing(0,10) print result
but note above, new list, result = []
, being created in testing
each time called.
Comments
Post a Comment