using 'global' across source files.
Remco Gerlich
scarblac at pino.selwerd.nl
Tue Jan 2 09:18:46 EST 2001
Bram Stolk <bram at sara.nl> wrote in comp.lang.python:
> Remco,
>
> Many thanks for your reply.
> However, your suggested changes do not fix the problem.
>
> I have now:
>
> # funcs.py
>
> def change_val() :
> global val
> val = val * 2
>
>
>
> # prog.py
>
> val = 100
>
> import funcs
>
>
> funcs.change_val()
> print val
You need "print funcs.val" now (just like you call the function with
"funcs.change_val()).
Using only import means you have to give the module's name every time,
but without that Python will never know if the value in the funcs module
has changed.
"global" just means "global inside this module".
--
Remco Gerlich
More information about the Python-list
mailing list