csvkit.unicsv¶
This module contains unicode aware replacements for csv.reader() and csv.writer(). The implementations are largely copied from examples in the csv module documentation.
These classes are available for Python 2 only. The Python 3 version of csv supports unicode internally.
Note
You probably don’t want to use these classes directly. Try the csvkit module.
- class csvkit.unicsv.UTF8Recoder(f, encoding)¶
Iterator that reads an encoded stream and reencodes the input to UTF-8.
- next()¶
- class csvkit.unicsv.UnicodeCSVReader(f, encoding='utf-8', maxfieldsize=None, **kwargs)¶
A CSV reader which will read rows from a file in a given encoding.
- next()¶
- line_num¶
- class csvkit.unicsv.UnicodeCSVWriter(f, encoding='utf-8', **kwargs)¶
A CSV writer which will write rows to a file in the specified encoding.
- NB: Optimized so that eight-bit encodings skip re-encoding. See:
- https://github.com/onyxfish/csvkit/issues/175
- writerow(row)¶
- writerows(rows)¶
- class csvkit.unicsv.UnicodeCSVDictReader(f, fieldnames=None, restkey=None, restval=None, *args, **kwargs)¶
Defer almost all implementation to csv.DictReader, but wraps our unicode reader instead of csv.reader().
- fieldnames¶
- next()¶
- class csvkit.unicsv.UnicodeCSVDictWriter(f, fieldnames, restval='', extrasaction='raise', *args, **kwds)¶
Defer almost all implementation to csv.DictWriter, but wraps our unicode writer instead of csv.writer().
- writerow(rowdict)¶
- writerows(rowdicts)¶
- writeheader()¶