Skip to main content

Backport of Python 3 csv module

Project description

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

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.

License

This is a port of the csv module in the Python 3 standard libary. Because of this, backports.csv follows the same license as Python, whatever that may be at any given point in time.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backports.csv-1.0.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

backports.csv-1.0.2-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file backports.csv-1.0.2.tar.gz.

File metadata

File hashes

Hashes for backports.csv-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2d7cd76b4fdf3f9af40e558a1a86276dda2b71f74bcde3d09dca4eed70029d10
MD5 b740969aecbcab8279750b51b4bd6cc4
BLAKE2b-256 ac34f703cabd12c7f6ec9d6079b7963755f1212bcf77235f622d28a5141620bc

See more details on using hashes here.

File details

Details for the file backports.csv-1.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for backports.csv-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 903a9a08e50e38d58d170ec5450a9d065ea1c92f52e6158d72f41ae8a0d02337
MD5 7485026f940fd6d37913ffe8a5ccf8fa
BLAKE2b-256 5ae74a4add3aed4f65c629ae7c8c07ae9a47ed9a5b824c1ee9663d4abc38d4eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page