Skip to content

Commit

Permalink
fix codec issues on python 2 and pypy
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed May 9, 2017
1 parent 8624430 commit c53cb3c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions unihan_tabular/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
unicode_literals, with_statement)

import argparse
import codecs
import fileinput
import glob
import json
import os
import sys
import zipfile
Expand Down Expand Up @@ -422,7 +424,7 @@ def export_csv(data, destination, fields):
data = listify(data, fields)
_file = '%s.csv' % destination

with open(_file, 'w+') as f:
with codecs.open(_file, 'w', encoding='utf-8') as f:
if PY2:
csvwriter = UnicodeWriter(f)
else:
Expand All @@ -433,15 +435,14 @@ def export_csv(data, destination, fields):

def export_json(data, destination):
_file = '%s.json' % destination
with open(_file, 'w+') as f:
import json
with codecs.open(_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
print('Saved output to: %s' % _file)


def export_yaml(data, destination):
_file = '%s.yaml' % destination
with open(_file, 'w+') as f:
with codecs.open(_file, 'w', encoding='utf-8') as f:
yaml.safe_dump(data, stream=f,
allow_unicode=True,
default_flow_style=False)
Expand Down

0 comments on commit c53cb3c

Please sign in to comment.