7.4. String Pprint
7.4.1. Example
from pprint import pprint
data = [
{'firstname': 'Mark', 'lastname': 'Watney'},
{'firstname': 'Melissa', 'lastname': 'Lewis'},
{'firstname': 'Rick', 'lastname': 'Martinez'},
]
pprint(data)
# [{'firstname': 'Mark', 'lastname': 'Watney'},
# {'firstname': 'Melissa', 'lastname': 'Lewis'},
# {'firstname': 'Rick', 'lastname': 'Martinez'}]
from pprint import pformat
data = [
{'firstname': 'Mark', 'lastname': 'Watney'},
{'firstname': 'Melissa', 'lastname': 'Lewis'},
{'firstname': 'Rick', 'lastname': 'Martinez'},
]
# returns formatted data
my_string = pformat(data)