passing global data to a function

beliavsky at aol.com beliavsky at aol.com
Mon Dec 1 11:55:38 EST 2003


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.




More information about the Python-list mailing list