Weird scope error

Michael Torrie torriem at gmail.com
Sat Apr 5 17:08:51 EDT 2008


Rory McKinley wrote:
> Gary Herron wrote:
> <snip>
>> Python has no such thing as this kind of a "global scope".   (True, each 
>> module has its own global scope, but that's not what you are talking 
>> about.)   So you'll have to fix the import for *every* module that needs 
>> access to ElementTree.    You might make the change as you mentioned 
>> above for each, but really, I think you should just make ElementTree 
>> directly importable by either installing it normally or including 
>> .../xml/etree in your PYTHONPATH
> <snip>
> 
> Thank you Gary and Kay for the response
> 
> My apologies for being dense with regard to this: If I understand your 
> responses correctly, the "from xml.etree import ElementTree" that I 
> inserted is failing? And that is why I am getting the NameError in the 
> method? Is Python just ignoring the failure?

No.  Your import is fine.  It imports "ElementTree" into the namespace
of your current module/program.  The problem is that the
elementtidy.TidyHTMLTreeBuilder module (not your code) is also trying to
import ElementTree into it's own namespace, which is failing, because
ElementTree itself isn't in the python path, but rather is in xml.etree.
 You need to either fix all these imports in these other modules (that
are probably in the site_packages folder), or modify the python import
path so that it can find ElementTree directly.  Again the problem isn't
in your code, but rather in the other modules.

> 
> 
> 
> Rory




More information about the Python-list mailing list