python - export data from csv file containing unicode characters -
i export data csv file contains unicode strings.
previously tried python script works fine ascii data only. won't support unicode stuff either:
#! /usr/bin/env python import csv csv.register_dialect('custom',delimiter=',' doublequote=true, escapechar=none, quotechar='"', quoting=csv.quote_minimal, skipinitialspace=false) open('input.csv') ifile: data = csv.reader(ifile, dialect='custom') record in data: i, field in enumerate(record): print (" <field%s>" % + field + "</field%s>" % i)
traceback (most recent call last): record in data: _csv.error: line contains null byte
use unicode-csv library instead
https://github.com/jdunck/python-unicodecsv
import unicodecsv csv open('input.csv') ifile: rows = [row row in csv.reader(ifile, encoding='utf-8')] print rows
Comments
Post a Comment