开发小技巧
Posted shaohef
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发小技巧相关的知识,希望对你有一定的参考价值。
1. pritty print xml
from bs4 import BeautifulSoup xml = ‘<group> <id>base</id> <name>Base</name> <default>false</default> <uservisible>false</uservisible> <packagelist> <packagereq requires="ruby" type="conditional">rubygem-abrt</packagereq> </packagelist> </group>‘ print(BeautifulSoup(xml, "xml").prettify())
XML=‘<group> <id>base</id> <name>Base</name> <default>false</default> <uservisible>false</uservisible> <packagelist> <packagereq requires="ruby" type="conditional">rubygem-abrt</packagereq> </packagelist> </group>‘ python -c "from bs4 import BeautifulSoup; print(BeautifulSoup(‘$XML‘, "xml").prettify())"
2. python
d = {‘a‘:1, ‘b‘:2, ‘c‘:{‘a‘:1}}
import json print(json.dumps(d, indent=4))
以上是关于开发小技巧的主要内容,如果未能解决你的问题,请参考以下文章