Skip to content

Commit

Permalink
decoder: unicode encoding fix by Anoop Sarkar and Chung-hye Han (Simo…
Browse files Browse the repository at this point in the history
…n Fraser); resolves #1
  • Loading branch information
mitcho committed Mar 4, 2016
1 parent f94fbb7 commit 85584ea
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lister.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
"""
Turk Lister
mitcho (Michael Yoshitaka Erlewine), [email protected], May 2013
Michael Yoshitaka ERLEWINE, [email protected], May 2013
Takes an items file and produces a Turk items CSV file and a decode CSV file.
Expand All @@ -13,7 +13,7 @@
copyright and licensing terms are unclear.
The MIT License (MIT)
Copyright (c) 2013 Michael Yoshitaka Erlewine
Copyright (c) 2013--2016 Michael Yoshitaka ERLEWINE and contributors
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
Expand Down Expand Up @@ -55,7 +55,7 @@ def graceful_exit():
pass

def graceful_write_csv(filename, data, keys = False):
from csv import DictWriter
import csv

if keys is False:
keys = data[0].keys()
Expand All @@ -64,12 +64,13 @@ def graceful_write_csv(filename, data, keys = False):

with open(filename, 'wb') as f:
# setting keys here fixes the order of columns
writer = DictWriter(f, keys, extrasaction = 'ignore')
writer = csv.DictWriter(f, keys, extrasaction = 'ignore', quoting = csv.QUOTE_NONNUMERIC)

# use this cumbersome line instead of writeheader() for python 2.6 compat:
writer.writerow(dict(zip(keys, keys)))
# encode utf8 on writerow, thanks to Anoop Sarkar:
for row in data:
writer.writerow(row)
writer.writerow({k: v.encode('utf8') if type(v) is unicode else v for k, v in row.items()})

def lcm(numbers):
from fractions import gcd
Expand Down

0 comments on commit 85584ea

Please sign in to comment.