import statement / ElementTree

mirandacascade at yahoo.com mirandacascade at yahoo.com
Sat Nov 5 03:48:47 CET 2005


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

Currently:

1) Folder structure:

\workarea\ <- ElementTree files reside here
  \xml\
    \dom\
    \parsers\
    \sax\

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 ElementTree.py; 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:
	__init__.py (this file contains only comments)
	ElementInclude.py
	ElementPath.py
	ElementTree.py
	HTMLTreeBuilder.py
	SgmlopXMLTreeBuilder.py
	SimpleXMLTreeBuilder.py
	SimpleXMLWriter.py
	TidyHTMLTreeBuilder.py
	TidyTools.py
	XMLTreeBuilder.py

Want to change things as follows:

Folder structure:

\workarea\ <- ElementTree files no longer here
  \xml\
    \dom\
    \elementtree\ <- ElementTree files reside here
    \parsers\
    \sax\

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 ElementTree.py 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
ElementTree.py 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