Last active
June 23, 2016 06:25
-
-
Save spikeekips/aa5f863166c1c4caa73402ae808f019d to your computer and use it in GitHub Desktop.
한글이 포함된 python literal들을 유니코드세트 대신 한글 그대로 출력. (http://m.egloos.zum.com/mcchae/v/11076302 참고)
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 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