本文介绍了在elementtree中使用SimpleXMLTreeBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个应用程序与django和elementtree,并将其部署到生产服务器,我发现它正在运行python 2.4。我已经能够捆绑elementtree,但是现在我收到错误:

 没有名为expat的模块;使用SimpleXMLTreeBuilder

不幸的是,我无法升级python,所以我卡住了我所得到的。如何使用SimpleXMLTreeBuilder作为解析器和/或需要重写代码?

解决方案

如果您有第三方模块想要使用ElementTree(和依赖于XMLTreeBuilder),您可以将ElementTree的XMLTreeBuilder定义更改为SimpleXMLTreeBuilder提供的定义,如下所示:

  from xml.etree import ElementTree#part of python distribution 
from elementtree import SimpleXMLTreeBuilder#部分代码库
ElementTree.XMLTreeBuilder = SimpleXMLTreeBuilder.TreeBuilder

现在,ElementTree会随时调用SimpleXMLTreeBuilder。



另请参见:


I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error:

"No module named expat; use SimpleXMLTreeBuilder instead"

Unfortunately i cannot upgrade python so im stuck with what i got. How do i use SimpleXMLTreeBuilder as the parser and/or will i need to rewrite code?

解决方案

If you have third party module that wants to use ElementTree (and XMLTreeBuilder by dependency) you can change ElementTree's XMLTreeBuilder definition to the one provided by SimpleXMLTreeBuilder like so:

from xml.etree import ElementTree # part of python distribution
from elementtree import SimpleXMLTreeBuilder # part of your codebase
ElementTree.XMLTreeBuilder = SimpleXMLTreeBuilder.TreeBuilder

Now ElementTree will always use the SimpleXMLTreeBuilder whenever it's called.

See also: http://groups.google.com/group/google-appengine/browse_thread/thread/b7399a91c9525c97

这篇关于在elementtree中使用SimpleXMLTreeBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:05