Why do directly imported variables behave differently than those attached to imported module?

Dun Peal dunpealer at gmail.com
Tue May 3 14:51:03 EDT 2011


OK, I understand now.

`from foo import var` means "create a module-global name `var` inside
the current module, and have it point at the object `foo.var` is
pointing at (following its evaluation)".

Naturally, regardless of whether `foo.var` ever changes, the global
`var` of the current module still points at the original object
`foo.var` was pointing to at the time of the `var = foo.var`
assignment.

Thanks, D.



More information about the Python-list mailing list