package elementtree doesn't work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • špela
    New Member
    • Dec 2010
    • 2

    package elementtree doesn't work

    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\li b\site-packages\elemen ttree\ElementTr ee.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>KOORD INATE - COORDINATES</h3>')
    Traceback (most recent call last):
    File "<pyshell#1 1>", line 1, in <module>
    feed('<h3>KOORD INATE - COORDINATES</h3>')
    NameError: name 'feed' is not defined
    >>> parse('<h3>KOOR DINATE - COORDINATES</h3>')
    Traceback (most recent call last):
    File "<pyshell#1 2>", line 1, in <module>
    parse('<h3>KOOR DINATE - COORDINATES</h3>')
    NameError: name 'parse' is not defined

    please, help.
    Špela
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I works on my system. Note that only 'ElementPath' and 'ElementTree' are available when importing * from elementtree:
    Code:
    >>> from elementtree import ElementTree
    >>> import elementtree as ET
    >>> dir(ET)
    ['ElementPath', 'ElementTree', '__builtins__', '__doc__', '__file__', '__name__', '__path__']
    >>> dir(ET.ElementTree)
    ['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']
    >>>

    Comment

    • špela
      New Member
      • Dec 2010
      • 2

      #3
      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\li b\site-packages\elemen ttree\ElementTr ee.py", line 794, in <module>
      _escape = re.compile(eval (r'u"[&<>\"\u0080-\uffff]+"'))
      File "<string>", line 1
      u"[&<>\"\u0080-\uffff]+"
      ^
      SyntaxError: invalid syntax
      >>>

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Try executing this code on your system:
        Code:
        >>> import re
        >>> _escape = re.compile(eval(r'u"[&<>\"\u0080-\uffff]+"'))
        >>> _escape
        <_sre.SRE_Pattern object at 0x00A71950>
        >>>
        That appears to be where the import is failing. What version of Python are you in?

        Comment

        Working...