Created
August 26, 2013 08:19
-
-
Save aoshiman/6339159 to your computer and use it in GitHub Desktop.
Pythonでコマンドライン時のListやDictを整形して表示させる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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