I wonder if there is an easy way to format Strings of dict-outputs such as this:
{
\'planet\' : {
\'name\' : \'Earth\',
\'has\' : {
\'plants\
Use pprint
import pprint
x = {
'planet' : {
'name' : 'Earth',
'has' : {
'plants' : 'yes',
'animals' : 'yes',
'cryptonite' : 'no'
}
}
}
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(x)
This outputs
{ 'planet': { 'has': { 'animals': 'yes',
'cryptonite': 'no',
'plants': 'yes'},
'name': 'Earth'}}
Play around with pprint formatting and you can get the desired result.