import statement / ElementTree

mirandacascade at mirandacascade at
Sat Nov 5 03:48:47 CET 2005

O/S: Windows 2K
Vsn of Python: 2.4


1) Folder structure:

\workarea\ <- ElementTree files reside here

2) The folder \workarea\ is in the path.

3) A script (which is working) makes calls to the Element(),
SubElement(), tostring() and XML() methods within; the
script is organized as follows:

# top of file; not within any function/mehtod
import ElementTree

<examples of various calls within the module>

root = ElementTree.Element('request')
pscifinq = ElementTree.SubElement(root, 'pscifinq')
bank = ElementTree.SubElement(pscifinq, 'bank')
bank.text = '1'
inquiryString = ElementTree.tostring(root)

4) the term 'ElementTree files' referenced above refers to the
following files: (this file contains only comments)

Want to change things as follows:

Folder structure:

\workarea\ <- ElementTree files no longer here
    \elementtree\ <- ElementTree files reside here

I tried changing the

import ElementTree

statement to:

import xml.elementtree.ElementTree

The result of changing the folder structure and the import statement
was the following error:

    import xml.elementtree.ElementTree

ImportError: No module named elementtree.ElementTree

I verified that the file really does reside in the
\workarea\xml\elementtree\ folder.  Assuming that I really want the
ElementTree files to reside in the \workarea\xml\elementtree\ folder,
what changes must I make such that the script can locate the file? I have a hunch that there is something obvious
that I am missing in the import statement; is it possible to accomplish
this by changing only the import statement rather than changing each of
the calls to the Element(), SubElement(), XML() and tostring() methods.

More information about the Python-list mailing list