By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,922 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,922 IT Pros & Developers. It's quick & easy.

package elementtree doesn't work

P: 2
Hi.
I have installed elementtree to python, but it now doesn't work:

>>> from elementtree import ElementTree
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
from elementtree import ElementTree
File "C:\Program Files\Python\lib\site-packages\elementtree\ElementTree.py", line 794, in <module>
_escape = re.compile(eval(r'u"[&<>\"\u0080-\uffff]+"'))
File "<string>", line 1
u"[&<>\"\u0080-\uffff]+"
^
SyntaxError: invalid syntax

Python does not complain if I write
from elementtree import * but no function is working (or I just don't know how to use it):

>>> from elementtree import *
>>>
>>> feed('<h3>KOORDINATE - COORDINATES</h3>')
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
feed('<h3>KOORDINATE - COORDINATES</h3>')
NameError: name 'feed' is not defined
>>> parse('<h3>KOORDINATE - COORDINATES</h3>')
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
parse('<h3>KOORDINATE - COORDINATES</h3>')
NameError: name 'parse' is not defined

please, help.
Špela
Dec 2 '10 #1
Share this Question
Share on Google+
3 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
I works on my system. Note that only 'ElementPath' and 'ElementTree' are available when importing * from elementtree:
Expand|Select|Wrap|Line Numbers
  1. >>> from elementtree import ElementTree
  2. >>> import elementtree as ET
  3. >>> dir(ET)
  4. ['ElementPath', 'ElementTree', '__builtins__', '__doc__', '__file__', '__name__', '__path__']
  5. >>> dir(ET.ElementTree)
  6. ['Comment', 'DefaultParserAPI', 'Element', 'ElementPath', 'ElementTree', 'PI', 'ProcessingInstruction', 'QName', 'SubElement', 'TreeBuilder', 'VERSION', 'XML', 'XMLID', 'XMLTreeBuilder', '_Element', '_ElementInterface', '_SimpleElementPath', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_encode', '_encode_entity', '_escape', '_escape_attrib', '_escape_cdata', '_escape_map', '_iterparse', '_namespace_map', '_raise_serialization_error', 'default_parser_api', 'dump', 'fixtag', 'fromstring', 'iselement', 'iterparse', 'parse', 'parser_api', 're', 'string', 'sys', 'tostring']
  7. >>> 
Dec 2 '10 #2

P: 2
it still doesn't work:
>>> from elementtree import ElementTree
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
from elementtree import ElementTree
File "C:\Program Files\Python\lib\site-packages\elementtree\ElementTree.py", line 794, in <module>
_escape = re.compile(eval(r'u"[&<>\"\u0080-\uffff]+"'))
File "<string>", line 1
u"[&<>\"\u0080-\uffff]+"
^
SyntaxError: invalid syntax
>>>
Dec 11 '10 #3

bvdet
Expert Mod 2.5K+
P: 2,851
Try executing this code on your system:
Expand|Select|Wrap|Line Numbers
  1. >>> import re
  2. >>> _escape = re.compile(eval(r'u"[&<>\"\u0080-\uffff]+"'))
  3. >>> _escape
  4. <_sre.SRE_Pattern object at 0x00A71950>
  5. >>> 
That appears to be where the import is failing. What version of Python are you in?
Dec 12 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.