diff --git a/gramps/gen/utils/docgen/csvtab.py b/gramps/gen/utils/docgen/csvtab.py index dd9e3aced..dabbd1591 100644 --- a/gramps/gen/utils/docgen/csvtab.py +++ b/gramps/gen/utils/docgen/csvtab.py @@ -50,7 +50,7 @@ class CSVTab(TabbedDoc): else: self.filename = filename - self.f = open(self.filename, "wb") + self.f = open(self.filename, "w") self.writer = csv.writer(self.f) def close(self): diff --git a/gramps/plugins/export/exportcsv.py b/gramps/plugins/export/exportcsv.py index 208f9f4c6..a206ddbab 100644 --- a/gramps/plugins/export/exportcsv.py +++ b/gramps/plugins/export/exportcsv.py @@ -154,15 +154,22 @@ class UnicodeWriter(object): self.encoder = codecs.getencoder(encoding) def writerow(self, row): - self.writer.writerow([s.encode('utf-8') for s in row]) - # Fetch UTF-8 output from the queue ... - data = self.queue.getvalue() - data = data.decode('utf-8') + if sys.version_info[0] < 3: + self.writer.writerow([s.encode('utf-8') for s in row]) + # Fetch UTF-8 output from the queue ... + data = self.queue.getvalue() + data = data.decode('utf-8') + else: + self.writer.writerow(row) + data = self.queue.getvalue() + #in python3, StringIO self.queue returns unicode! + #data now contains the csv data in unicode # ... and reencode it into the target encoding data, length = self.encoder(data) # write to the target stream self.stream.write(data) - # empty queue + # empty queue, go to start position, then truncate + self.queue.seek(0) self.queue.truncate(0) def writerows(self, rows):