[Short sentence] [Python] Format and print lists and dictionaries

As I learned today, it has been the standard since ancient times. Use pprint. (Python3.x, Python 2.x )) If you want to customize it, you have to read the document, but if you want to "measure it well", you can use it.

from pprint import pprint

pprint(my_something)

Example:

code


import http.client
from pprint import pprint

conn = http.client.HTTPSConnection('python.org')
conn.request('GET', '/')
resp = conn.getresponse()
pprint(resp.getheaders())

stdout


[('Server', 'nginx'),
 ('Date', 'Sat, 28 May 2016 06:51:23 GMT'),
 ('Content-Type', 'text/html'),
 ('Content-Length', '178'),
 ('Location', 'https://www.python.org/'),
 ('Strict-Transport-Security', 'max-age=315360000; preload')]

Please use it for debugging output.

Recommended Posts

[Short sentence] [Python] Format and print lists and dictionaries
Understand python lists, dictionaries, and so on.
Python3 | Lists, Tuples, Dictionaries
Python lists, tuples, dictionaries
Save lists, dictionaries and tuples to external files python
Python indentation and string format
How to use lists, tuples, dictionaries, and sets
[Python3] Automatic sentence generation using janome and markovify
Python string format
Python string format
format in python
python2 series / 3 series, character code and print statement / command line
Read and analyze arff format dataset with python scipy.io
Read json file with Python, format it, and output json
[Python] Extract only numbers from lists and character strings
[Super easy! ] How to display the contents of dictionaries and lists including Japanese in Python