Import conundrum

Cliff pythonista at uk2.net
Tue Apr 23 04:38:55 EDT 2002


If I put the following Python 2.1 script in a file called 'xml.py':

   from xml.dom.minidom import parseString
   dom = parseString('<?xml version="1.0" ?><test/>')
   print dom.writexml(sys.stdout)

and then try to run it on Windows NT I get the following:

   Traceback (most recent call last):
     File "C:\home\temp\xml.py", line 5, in ?
       from xml.dom.minidom import parseString
     File "C:\home\temp\xml.py", line 5, in ?
       from xml.dom.minidom import parseString
   ImportError: No module named dom.minidom

If I rename the file to something else, then everything is as expected. 
What I am interested to know is whether this is 'correct' behaviour, or am 
I doing something really stupid?

I ask, because I would personally expect the Python interpreter to know the 
difference between the file called 'xml.py' and the library path 'xml.dom' 
(which I would expect to be mapped to .\xml\dom on Windows).

And there I was thinking I understood this Python stuff... ;-)

Cliff



More information about the Python-list mailing list