Import confusion
Fredrik Lundh
fredrik at pythonware.com
Sat Apr 7 11:20:27 EDT 2001
Kristian Ovaska wrote:
> From your document:
> "from X import * imports the module X, and _creates references_ in the
> current name space to all public symbols defined by that module"
>
> I underlined the part that confuses me. m1.x should be a reference to
> m2.x, no?
no, it's a reference to the *object* pointed to by m2.x, at the time
from-import was executed. your setX function changes what m2.x
refers to, not the object. m1 won't notice.
for more info on the difference between names and objects, see:
http://effbot.org/guides/python-objects.htm
and the recent "changing global variables" thread.
if it's still not clear, remember the fourth from-import rule: don't
use from-import unless you know exactly what you're doing ;-)
Cheers /F
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list