12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[短文][Python]リストや辞書などを整形してprint

Posted at

今日知ったけど、実は大昔から標準でありました。pprintを使います。 (Python3.x, Python 2.x)
カスタマイズするなら、ドキュメントを読まねばなりませんが、「良きに計らえ」でよければ、これだけで使えます。

from pprint import pprint

pprint(my_something)

例:

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')]

デバッグ用出力などにどうぞ。

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?