Skip to content

Instantly share code, notes, and snippets.

@spikeekips
Last active June 23, 2016 06:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spikeekips/aa5f863166c1c4caa73402ae808f019d to your computer and use it in GitHub Desktop.
Save spikeekips/aa5f863166c1c4caa73402ae808f019d to your computer and use it in GitHub Desktop.
한글이 포함된 python literal들을 유니코드세트 대신 한글 그대로 출력. (http://m.egloos.zum.com/mcchae/v/11076302 참고)
# -*- coding: utf-8 -*-
import pprint
class MyPrettyPrinter(pprint.PrettyPrinter):
def format(self, _object, context, maxlevels, level):
if isinstance(_object, unicode):
return "'%s'" % _object.encode('utf8'), True, False
elif isinstance(_object, str):
_object = unicode(_object, 'utf8')
return "'%s'" % _object.encode('utf8'), True, False
return pprint.PrettyPrinter.format(self, _object, context, maxlevels, level)
if __name__ == '__main__':
MyPrettyPrinter().pprint(dict(a=u'뉴스타파 윤원님 바보.'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment