I wonder if there is an easy way to format Strings of dict-outputs such as this:
{
\'planet\' : {
\'name\' : \'Earth\',
\'has\' : {
\'plants\
Depending on what you're doing with the output, one option is to use JSON for the display.
import json
x = {'planet' : {'has': {'plants': 'yes', 'animals': 'yes', 'cryptonite': 'no'}, 'name': 'Earth'}}
print json.dumps(x, indent=2)
Output:
{
"planet": {
"has": {
"plants": "yes",
"animals": "yes",
"cryptonite": "no"
},
"name": "Earth"
}
}
The caveat to this approach is that some things are not serializable by JSON. Some extra code would be required if the dict contained non-serializable items like classes or functions.