Fix pokedex dump under Python 2 AND 3, at the same time even

This commit is contained in:
Eevee (Lexy Munroe) 2015-11-04 20:10:27 -08:00
parent b581c5205a
commit 54ea67a804

View file

@ -402,9 +402,13 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None):
else: else:
filename = '%s/%s.csv' % (directory, table_name) filename = '%s/%s.csv' % (directory, table_name)
writer = csv.writer(io.open(filename, 'wb'), lineterminator='\n') # CSV module only works with bytes on 2 and only works with text on 3!
if six.PY3:
columns = [col.name.encode('utf8') for col in table.columns] writer = csv.writer(open(filename, 'w', newline=''), lineterminator='\n')
columns = [col.name for col in table.columns]
else:
writer = csv.writer(open(filename, 'wb'), lineterminator='\n')
columns = [col.name.encode('utf8') for col in table.columns]
# For name tables, always dump rows for official languages, as well as # For name tables, always dump rows for official languages, as well as
# for those in `langs` if specified. # for those in `langs` if specified.
@ -442,7 +446,9 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None):
elif val == False: elif val == False:
val = '0' val = '0'
else: else:
val = six.text_type(val).encode('utf-8') val = six.text_type(val)
if not six.PY3:
val = val.encode('utf8')
csvs.append(val) csvs.append(val)