Odd behaviour on importing variable from module

rs387 rstarkov at gmail.com
Sat Aug 23 15:28:20 CEST 2008

> 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.

Ah right, this does indeed explain what I'm seeing. For some reason I
thought "from module import variable" magically makes "variable" an
"alias", so to speak, for "module.var", which of course it does not.

> Yes. Think of
> from module import var
> as a shortcut for
> import module
> var = module.var
> del module

Good tip, I'll remember this. Thanks very much Fredrik, Peter!


More information about the Python-list mailing list