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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -