发布于 2014-12-10 20:29:25
这一点:
`from libs.dicttoxml_fast.dicttoxml_fast import dicttoxml` 无法使用当前的dicttoxml_fast模块。您可以通过以下方式导入:
`from libs.dicttoxml_fast import dicttoxml_fast as dicttoxml`但这不会使原始dicttoxml中的其他函数使用您自己的convert_list版本。如果这就是你的计划,你要么派生原始的(FWIW作者可能会对你自己的实现感兴趣,如果它严格等价且更快的话),或者monkeypatch:
# dicttoxml_fast.py
import dicttoxml
from dicttoxml import *
def convert_list(items, ids, parent, attr_type):
# your code here
# apply the monkeypatch
dicttoxml.convert_list = convert_list然后在客户机代码中使用from libs.dicttoxml_fast.dicttoxml_fast import dicttoxml。
https://stackoverflow.com/questions/27399930
复制相似问题