Created
April 10, 2018 06:44
-
-
Save akkefa/bce01140f33a6b3878f4b8807e09585b to your computer and use it in GitHub Desktop.
Python 3: Save unicode(Urdu) string to file not using '\uXXXX' but using UTF-8.
This file contains hidden or 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': 'پنجاب' } | |
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