Odd behaviour on importing variable from module

Fredrik Lundh fredrik at pythonware.com
Sat Aug 23 14:30:56 CEST 2008


rs387 wrote:

> I've found the following behaviour on importing a variable from a
> module somewhat odd. The behaviour is identical in Python 2.5 and
> 3.0b2.

the construct

     from oddmodule import OddVariable, OddFunction

assigns the *values* of the given module names to new variables in the 
importing module's namespace.  that is, you're binding new names to the 
values the variables happen to have when the from-import statement is 
executed.  given this, the behaviour should be no more surprising than

     A = "value"
     B = A
     A = "new value"
     print B # prints "value"

reading up on how objects and names work in Python could be a good idea; 
this page might help:

     http://effbot.org/zone/python-objects.htm

</F>




More information about the Python-list mailing list