Skip to main content
Latest Version https://travis-ci.org/ryanhiebert/backports.csv.svg?branch=master Join the chat at https://gitter.im/ryanhiebert/backports.csv Requirements Status

The API of the csv module in Python 2 is drastically different from the csv module in Python 3. This is due, for the most part, to the difference between str in Python 2 and Python 3.

The semantics of Python 3’s version are more useful because they support unicode natively, while Python 2’s csv does not.

Installation

pip install backports.csv

Usage

First make sure you’re starting your file off right:

from backports import csv

Then be careful with your files to handle the encoding. If you’re working with a binary file-like object, io.TextIOWrapper can be very helpful. If you’re dealing with a file, you can just use io.open instead of Python 2’s open builtin, and it works just like Python 3’s builtin open.

from backports import csv
import io

def read_csv(filename):
    with io.open(filename, newline='', encoding='utf-8') as f:
        for row in csv.reader(f):
            yield row

def write_csv(filename, rows):
    with io.open(filename, 'w', newline='', encoding='utf-8') as f:
        writer = csv.writer(f)
        for row in rows:
            writer.writerows(row)

Note: It should always be safe to specify newline='', since the csv module does its own (universal) newline handling.

1.0.4 (2017-02-17)

  • Return write value from writerow. (#20) - thanks to @therg

1.0.3 (2017-01-23)

  • Add LICENSE file (#18).

1.0.2 (2016-09-15)

  • Avoid quoting any numeric types when using QUOTE_NONNUMERIC. - thanks to @torfsen for the bug report

1.0.1 (2016-02-11)

  • Better error messages for invalid dialects. - thanks to @kengruven for the bug report

1.0 (2016-02-11)

  • Initial Release

Metadata

Release files for backports.csv 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for backports.csv 1.0.4
File Size Uploaded
backports.csv-1.0.4.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for backports.csv 1.0.4
File Interpreter ABI Platform
backports.csv-1.0.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 25.0 kB

Release files / backports.csv-1.0.4.tar.gz

Download URL backports.csv-1.0.4.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d810b20839270df6261405286d3e864fc35a388217715d09049bee38373894b7
BLAKE2b-256 checksum
How to use checksums
22d3d6e03e02a310ffa1f2718ef0e44fb187b33e9ce2366185a57bd27d3b0f86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / backports.csv-1.0.4-py2.py3-none-any.whl

Download URL backports.csv-1.0.4-py2.py3-none-any.whl
Size 13.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7ab33513230b590de8d28c4a2ba3a204068d7e18d1bfe91a8a4817196b110e03
BLAKE2b-256 checksum
How to use checksums
866fa00aaeb99fc11eff0665800472db1c39dfc16f06990e4da708f82a5bf3ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page