Modules - problem

Robin Munn rmunn at pobox.com
Thu Oct 17 15:59:25 CEST 2002


In article <mailman.1034860224.9803.python-list at python.org>, A wrote:
> Hi,
> I would like to access a variable in one module from another module.For example
> 
> The main module is like this
> #############
> #Main modul z1.py
> import z3
> print "x variable=", z3.x
> ###########
> 
> where z3.py module is like
> 
> ########
> #My module z3.py
> global x
> x=11
> #########
> Now if I run z1.py for the first time it prints properly
> 
> x variable= 11
> 
> but if I do any  change in z3 module , it has no effect
> For example If I change in z3
> x=12
> I still get
>  x variable= 11
> Why?

Modules are only imported once no matter how many times the 'import' 
statement shows up. If you really want to re-import the z3 module, try 
doing a 'reload z3'.

> Thank you for help.
> Is it possible to name module with a different extension from py? For example is it possible 
> to import z3.cod file?
> Ladislav

I don't know; maybe someone else can answer this one. For myself, I 
think you would have to recompile your Python interpreter to change 
this, and I can't conceive why you would want to be deliberately 
incompatible with everyone else like that.

-- 
Robin Munn
rmunn at pobox.com



More information about the Python-list mailing list