By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,402 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,402 IT Pros & Developers. It's quick & easy.

Weird scope error

P: n/a
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
Apr 5 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.