Reputation: 29
I would like to print the following dictionary:
'test.com': {'@': {'NS': ['ns1.test.net', 'ns2.test.net']},
'api': {'A': ['123.122.2.1','121.161.51.29','111.30.12.14']}}
Like the following:
'test.com': {
'@': {
'NS': ['ns1.test.net', 'ns2.test.net']
},
'api': {
'A': ['123.122.2.1','121.161.51.29','111.30.12.14']
}
}
Thanks very much!
Upvotes: 1
Views: 89
Reputation: 59974
Simple solution with json
:
>>> import json
>>> data = {'test.com': {'@': {'NS': ['ns1.test.net', 'ns2.test.net']}, 'api': {'A': ['123.122.2.1', '121.161.51.29', '111.30.12.14']}}}
>>> print json.dumps(data,indent=4)
{
"test.com": {
"@": {
"NS": [
"ns1.test.net",
"ns2.test.net"
]
},
"api": {
"A": [
"123.122.2.1",
"121.161.51.29",
"111.30.12.14"
]
}
}
}
Upvotes: 2
Reputation: 20442
You can try the pprint module.
If you don't like the format the pprint
provides, then you will need to write your own method for printing the object.
Upvotes: 0