470,591 Members | 1,531 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Weird scope error


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 :

I receive the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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?

Apr 5 '08 #1
0 873

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by alice | last post: by
2 posts views Thread by Nils Emil P. Larsen | last post: by
11 posts views Thread by Afzal Mazhar | last post: by
13 posts views Thread by Joe Attardi | last post: by
2 posts views Thread by keepyourstupidspam | last post: by
2 posts views Thread by Matt Nordhoff | last post: by
8 posts views Thread by Tom P. | last post: by
9 posts views Thread by mrstevegross | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.