unicodecsv Library

0.14.1 · abandoned · verified Thu Apr 09

unicodecsv is a Python 2 library that provides a drop-in replacement for the standard library's `csv` module, adding robust Unicode support. The current version is 0.14.1, released in 2016. This library is effectively abandoned and is no longer maintained, primarily serving legacy Python 2 applications.

Warnings

Install

Imports

Quickstart

Demonstrates writing and reading Unicode data using `unicodecsv` with `io.BytesIO` to simulate file operations. This library is specifically designed for Python 2 to correctly handle Unicode CSV files.

import unicodecsv as csv
import io

# This example demonstrates unicodecsv in a Python 2-like environment.
# In Python 3, the standard `csv` module handles unicode correctly.

# Simulate a file-like object for writing (expecting bytes)
output_buffer = io.BytesIO()
writer = csv.writer(output_buffer, encoding='utf-8')
writer.writerow(['héllø', 'wørld', '😊'])
writer.writerow(['line 2', 'value 2', 'another'])

# Get the byte content written to the buffer
csv_bytes = output_buffer.getvalue()
print("unicodecsv: Written CSV bytes (Python 2 style):")
print(csv_bytes.decode('utf-8')) # Decode for printing in Python 3 console

# Simulate a file-like object for reading
input_buffer = io.BytesIO(csv_bytes)
reader = csv.reader(input_buffer, encoding='utf-8')

print("\nunicodecsv: Read CSV rows (Python 2 style):")
for row in reader:
    print(row)

# Expected output in a Python 2 environment would be lists of unicode strings.

view raw JSON →