Created
April 30, 2012 14:51
-
-
Save norioxkimura/2558970 to your computer and use it in GitHub Desktop.
Python 2.7: Save unicode string to file not using '\uXXXX' but using UTF-8.
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 json | |
from codecs import open | |
o = { 'text': u'木村' } | |
with open('foo.json', 'w', encoding= 'utf-8') as fp: | |
json.dump(o, fp, ensure_ascii= False) | |
with open('foo.json', 'r', encoding= 'utf-8') as fp: | |
print json.load(fp)['text'].encode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment