Weird scope error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rory McKinley

    Weird scope error

    Hi

    I am trying to use the TidyHTMLTreeBui lder module which is part of
    elementtidy, but I am getting what appears to be some sort of scope
    error and it is scrambling my n00b brain.

    The module file (TidyHTMLTreeBu ilder.py) tried to import ElementTree by
    doing the following:

    from elementtree import ElementTree

    This bombed, so after a bit of poking around I replaced it with :

    from xml.etree import ElementTree

    This appears to have worked. However, when I try and parse a file using
    the function :
    TidyHTMLTreeBui lder.parse('wea ther_ct.html')

    I receive the following error:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File
    "/usr/lib/python2.5/site-packages/elementtidy/TidyHTMLTreeBui lder.py",
    line 107, in parse
    return ElementTree.par se(source, TreeBuilder())
    NameError: global name 'ElementTree' is not defined


    The code producing the error is as follows:

    def parse(source):
    return ElementTree.par se(source, TreeBuilder())

    Surely, if the from... import has worked, ElementTree is in the global
    scope and should therefore be accessible to the function parse?

    Can anybody help?

    THanks
Working...