如何解决如何用漂亮的打印Python将字典写入xml文件?
Map params=getQueryMap(querystring);
String id=(String)params.get("id");
String anotherparam=(String)params.get("anotherparam");
尝试将此字典d = {"a":"a1234","b":"b5678","c":"c4554545"}
转换为d
,如下所示
xml
代码:
<?xml version="1.0" encoding="UTF-8" ?>
<test>
<a>a1234</a>
<b>b5678</b>
<c>c4554545</c>
</test>
尝试在xml输出上方进行打印,并进行漂亮的打印,但最终在from dicttoxml import dicttoxml
xml = dicttoxml(d,custom_root='test',attr_type=False)
# Above 'xml' is of type bytes here
xml = xml.decode("utf-8") # Converting bytes to string
print(xml) # prints,<?xml version="1.0" encoding="UTF-8" ?><test><a>a1234</a><b>b5678</b><c>c4554545</c></test>
以下获得了
(excludes <?xml version
如何漂亮地打印如下内容?
<test>
<a>a1234</a>
<b>b5678</b>
<c>c4554545</c>
</test>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。