Surprising difference in behavior between "import blah" and "from blah import thing"

Ben Finney bignose+hates-spam at benfinney.id.au
Thu May 8 18:35:23 EDT 2008


offby1 <eric.hanchrow at gmail.com> writes:

> Ah.  So from the point of view of mut.py, "thing" and "system.thing"
> are separate, unrelated variables;

No. Thinking of them as "variables" (with all the non-Python
terminological baggage that implies) will only exacerbate the
confusion.

"thing" and "system.thing" are separate *names*, that can be
independently bound to different objects or the same object.

> the former of which is initialized from the latter when mut says
> "from system import thing".

Rather, the name "thing" is bound to the same object as the name
"system.thing" at the time "from system import thing" is executed.
What happens to the name "system.thing" afterward has no effect on the
name "thing".

-- 
 \     "Listen: we are here on Earth to fart around. Don't let anybody |
  `\               tell you otherwise."  -- _Timequake_, Kurt Vonnegut |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list