Import confusion

Kristian Ovaska kristian.ovaska at helsinki.fi
Sat Apr 7 10:59:33 EDT 2001


"Fredrik Lundh" <fredrik at pythonware.com>:
>> Now, this prints 10. I'm confused. Could someone explain what's going
>> on?
>http://effbot.org/guides/import-confusion.htm

I'm afraid this still isn't clear. Let's see. When I use
from m2 import *,
it imports x and setX, but x doesn't point to the same x that setX
sees. There are two x's.

I confirmed this by adding this method to m2 and calling it from m1:
def printX():
	global x
	print x
It prints 10, while "print x" still prints 0.

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

-- 
Kristian Ovaska <kristian.ovaska at helsinki.fi>



More information about the Python-list mailing list