Skip to content

Instantly share code, notes, and snippets.

@guerbai
Created January 30, 2017 15:28
Show Gist options
  • Save guerbai/0c187901de22321681eff48309cf46af to your computer and use it in GitHub Desktop.
Save guerbai/0c187901de22321681eff48309cf46af to your computer and use it in GitHub Desktop.
Python输出格式化带中文的json文件.
# -*- coding:utf-8 -*-
import json
import codecs
a = { "name": "一个"}
b = json.dumps(a, indent=4)
print type(b)
f = codecs.open('test3.py', 'wb', encoding='utf-8')
f.write(b.decode("unicode_escape"))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment