passing global data to a function
Hans Nowak
hans at zephyrfalcon.org
Mon Dec 1 12:28:22 EST 2003
beliavsky at aol.com wrote:
> 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)
Try:
import funk
xx = 4.0
print funk.xpow(xx)
funk.ipow = 3
print funk.xpow(xx)
Of course, there might be a better way to do this than with globals... a class
comes to mind as one possible alternative.
HTH,
--
Hans (hans at zephyrfalcon.org)
http://zephyrfalcon.org/
More information about the Python-list
mailing list