python 中的字典转化成xml
看代码#!/usr/bin/env python# -*- coding: utf-8 -*-class DicXl(object):def dict_to_xml(self, params):def demo(params=params):str = ""for k, v in params.items(...
·
看代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class DicXl(object):
def dict_to_xml(self, params):
def demo(params=params):
str = ""
for k, v in params.items():
str += "<%s>""%s""<%s>" % (k, v, k) if not isinstance(v, dict) else "<%s>""%s""<%s>" % (k, demo(v), k)
message = "<MbfBody>" + str + "</MbfBody>"
return message
return demo
if __name__ == '__main__':
params = {"name": "小明", "age": 18, "hobby": "football", "other": {"name": "火云邪神"}}
print(DicXl().dict_to_xml(params)())
更多推荐
已为社区贡献5条内容
所有评论(0)