Skip to content

Instantly share code, notes, and snippets.

@aoshiman
Created August 26, 2013 08:19
Show Gist options
  • Save aoshiman/6339159 to your computer and use it in GitHub Desktop.
Save aoshiman/6339159 to your computer and use it in GitHub Desktop.
Pythonでコマンドライン時のListやDictを整形して表示させる
# -*- coding: utf-8 -*-
import re, pprint
def pp(obj):
"""
PrettyPrint for Python list and Dict
Usage
>>> data = {u"spam" : u"スパム", u"ham" : u"ハム", u"eggs" : u"エッグス"}
>>> print pp(data)
{ u'eggs': u'エッグス', u'ham': u'ハム', u'spam': u'スパム'}
"""
pp = pprint.PrettyPrinter(indent=4, width=160)
str = pp.pformat(obj)
return re.sub(r"\\u([0-9a-f]{4})", lambda x: unichr(int("0x"+x.group(1), 16)), str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment