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. 1 2986 mi************@yahoo.com wrote: O/S: Windows 2K Vsn of Python: 2.4
Currently:
1) Folder structure:
\workarea\ <- ElementTree files reside here \xml\ \dom\ \parsers\ \sax\
First point, XML DOM comes packaged with Python 2.4. (IIRC, Python XML
is, or was, a seperate project that made it into the Python
distribution--maybe it still makes its own releases. I presume you're
using one of those release in lieu of the version supplied with Python.
I only point this out in case you didn't realize the xml package is in
Python 2.4. My apologies if this comes across as presumptuous of me.)
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)
In the most recent version, ElementTree modules are part of the
elementtree package. Are you using an older version? If so, perhaps
you should get the latest version.
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
It looks like your version of ElementTree is a packaged version. The
file __init__.py normally appears only in packages; it's a mistake for
these files to have been in the workarea directory in the first place.
How did you install ElementTree?
Want to change things as follows:
Folder structure:
\workarea\ <- ElementTree files no longer here \xml\ \dom\ \elementtree\ <- ElementTree files reside here \parsers\ \sax\
Bad idea, I'd say. Generally, you shouldn't inject your own modules
into someone else's package system (unless you're working on someone
else's packages, to modify or enhance them). The xml package might
have been a slight exception to this, seeing how it's just a container
for several related packages, but it's in the Python distribution.
ElementTree modules are part of the elementtree package. You should
arrange your directories like this (and they should have been arranged
like this in the first place):
\workarea
\elementtree
\xml
\dom
\sax
...etc...
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'm guessing this exception is not happening with your import
statement, but with some other import in one of the ElementTree modules
(though in that case I'm not sure why it would have been working
before). I'd have to see the traceback to be sure. Generally, when
reporting an error, you should include a traceback.
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.
Well, if you arrange it as I advise, you shouldn't have a problem.
However, if you want to change only the import statements, you don't
want to do this:
import elementtree.ElementTree
That will import ElementTree but the you'd have to access it as
elementtree.ElementTree. Instead you should do this:
from elementtree import ElementTree
Carl Banks This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Greg Wilson |
last post by:
I'm trying to convert from minidom to ElementTree for handling XML,
and am having trouble with entities in DTDs. My Python script looks
like this:
...
|
by: alainpoint |
last post by:
Hello,
I use Elementtree to parse an elementary SVG file (in fact, it is one
of the examples in the "SVG essentials" book). More precisely, it is
the fig0201.svg file in the second chapter.
The...
|
by: Chris Spencer |
last post by:
Does anyone know how to make ElementTree preserve namespace prefixes in
parsed xml files? The default behavior is to strip a document of all
prefixes and then replace them autogenerated prefixes...
|
by: Steven Bethard |
last post by:
I'm having trouble using elementtree with an XML file that has some
gbk-encoded text. (I can't read Chinese, so I'm taking their word for
it that it's gbk-encoded.) I always have trouble with...
|
by: Steven Bethard |
last post by:
Ok, I finally have a PEP number. Here's the most updated version of the
"make" statement PEP. I'll be posting it shortly to python-dev.
Thanks again for the previous discussion and suggestions!...
|
by: mirandacascade |
last post by:
Situation is this:
1) I have inherited some python code that accepts a string object, the
contents of which is an XML document, and produces a data structure
that represents some of the content of...
|
by: Rick Muller |
last post by:
I'm a computational chemist who frequently dabbles in Python. A
collaborator sent me a huge XML file that at one point was evidently
modified by a now defunct java application. A sample of this...
|
by: Peter Pei |
last post by:
One bad design about elementtree is that it has different ways parsing a
string and a file, even worse they return different objects:
1) When you parse a file, you can simply call parse, which...
|
by: gray.bowman |
last post by:
I'm messing around with trying to write an xml file using
xml.etree.ElementTree. All the examples on the internet show the use
of ElementTree.write(), although when I try to use it it's not...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |