Weird scope error

Kay Schluehr kay.schluehr at gmx.net
Sat Apr 5 11:55:04 EDT 2008


On 5 Apr., 17:27, Rory McKinley <rorymckinleyli... at gmail.com> wrote:
> Hi
>
> I am trying to use the TidyHTMLTreeBuilder 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 (TidyHTMLTreeBuilder.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 :
> TidyHTMLTreeBuilder.parse('weather_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/TidyHTMLTreeBuilder.py",
> line 107, in parse
>      return ElementTree.parse(source, TreeBuilder())
> NameError: global name 'ElementTree' is not defined
>
> The code producing the error is as follows:
>
> def parse(source):
>      return ElementTree.parse(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

The problem stems from the fact that TidyHTMLTreeBuilder uses a
different import path assuming that the elementtree package is found
somewhere in the pythonpath e.g. in site-packages and not in the
builtins. I guess this problem will be resolved when you install the
elementree package again.



More information about the Python-list mailing list