Weird scope error

R

Rory McKinley

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
 
K

Kay Schluehr

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,296
Latest member
HeikeHolli

Latest Threads

Top