Correct JSON writing (Closes #596)
This commit is contained in:
parent
3cc687d486
commit
f4bfd65ff2
2 changed files with 15 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
import locale
|
||||
import os
|
||||
import re
|
||||
|
@ -175,6 +176,18 @@ else:
|
|||
assert type(s) == type(u'')
|
||||
print(s)
|
||||
|
||||
# In Python 2.x, json.dump expects a bytestream.
|
||||
# In Python 3.x, it writes to a character stream
|
||||
if sys.version_info < (3,0):
|
||||
def write_json_file(obj, fn):
|
||||
with open(fn, 'wb') as f:
|
||||
json.dump(obj, f)
|
||||
else:
|
||||
def write_json_file(obj, fn):
|
||||
with open(fn, 'w', encoding='utf-8') as f:
|
||||
json.dump(obj, f)
|
||||
|
||||
|
||||
def htmlentity_transform(matchobj):
|
||||
"""Transforms an HTML entity to a character.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue