lundi 29 septembre 2008

problème reading CSV in python

import codecs
codecs.open(sys.argv[1], "rb", encoding='utf-8')
au lieu de open()


ou ...

def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
# csv.py doesn't do Unicode; encode temporarily as UTF-8:
csv_reader = csv.reader(utf_8_encoder(unicode_csv_data), dialect=dialect, **kwargs)
for row in csv_reader:
# decode UTF-8 back to Unicode, cell by cell:
yield [unicode(cell, 'utf-8') for cell in row]
reader_src = unicode_csv_reader(codecs.open(sys.argv[1], "rb", encoding='utf-8'), delimiter=';', quoting=csv.QUOTE_ALL)

Aucun commentaire: