1. 程式人生 > >開發小技巧

開發小技巧

spa ref soup The color target false gem ger

1. pritty print xml

BeautifulSoup

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))

 

開發小技巧