Global variables in modules/functions

Peter Otten __peter__ at web.de
Fri Nov 19 18:46:58 EST 2004


Peter Otten wrote:

> A clean way to share data between different modules is to introduce
> another module and use a qualified name to access data in that module:
> 
> shared.py
> n = 1
> 
> main.py
> import shared
> import change
> 
> change.change_n()
> print n

Oops, that should be

print shared.n
 
> change.py
> import shared
> def change_n():
> shared.n = 2
> 




More information about the Python-list mailing list