B
beliavsky
How can I pass global data to function stored in a separate file?
For example, in file "funk.py" is the code
ipow = 2
def xpow(xx): return xx**ipow
and in "xfunk.py" is the code
from funk import xpow,ipow
xx = 4.0
print xpow(xx)
ipow = 3
print xpow(xx)
Running Python against xfunk.py, I get the output
16.0
16.0,
so the value of ipow in function xpow is not being changed. I want ipow to equal
4 in the 2nd call to xpow, so that the output would be
16.0
64.0
How can this be done? Thanks.
For example, in file "funk.py" is the code
ipow = 2
def xpow(xx): return xx**ipow
and in "xfunk.py" is the code
from funk import xpow,ipow
xx = 4.0
print xpow(xx)
ipow = 3
print xpow(xx)
Running Python against xfunk.py, I get the output
16.0
16.0,
so the value of ipow in function xpow is not being changed. I want ipow to equal
4 in the 2nd call to xpow, so that the output would be
16.0
64.0
How can this be done? Thanks.