Skip to content

Commit

Permalink
💚 limit the UnicodeWriter to python 2 only, #44
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Nov 10, 2017
1 parent c5656ac commit 2c539ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pyexcel_io/writers/csvw.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def writerow(self, row):
for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
if compact.PY2:
data = data.decode("utf-8")
data = data.decode("utf-8")
# ... and reencode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
Expand Down
16 changes: 10 additions & 6 deletions pyexcel_io/writers/csvz.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
import zipfile

from pyexcel_io._compact import StringIO
from pyexcel_io._compact import StringIO, PY2
from pyexcel_io.book import BookWriter
from pyexcel_io.constants import DEFAULT_SHEET_NAME, FILE_FORMAT_CSVZ

Expand All @@ -25,11 +25,15 @@ def __init__(self, zipfile, sheetname, file_extension, **keywords):

def set_sheet_name(self, name):
self.content = StringIO()
self.writer = UnicodeWriter(
self.content,
encoding=self._encoding,
**self._keywords
)
if PY2:
self.writer = UnicodeWriter(
self.content,
encoding=self._encoding,
**self._keywords
)
else:
import csv
self.writer = csv.writer(self.content, **self._keywords)

def close(self):
file_name = "%s.%s" % (self._native_sheet, self.file_extension)
Expand Down

0 comments on commit 2c539ec

Please sign in to comment.