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 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.writerow(row)

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

1.0.7 (2019-03-10)

  • Add tests to MANIFEST.in. - thanks to @jayvdb for the pull request

1.0.6 (2018-05-22)

  • Pass reader error messages along. (#28) This should help make errors more transparent. - thanks to @mpeteuil for the pull request

1.0.5 (2017-05-29)

  • Fix bug in README example. (#22) - thanks to @tantale for the bug report

  • Allow None as quotechar when using QUOTE_NONE. (#23) - thanks to @thanatos for the bug report

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

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.7.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

backports.csv-1.0.7-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.7.tar.gz.

File metadata

  • Download URL: backports.csv-1.0.7.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for backports.csv-1.0.7.tar.gz
Algorithm Hash digest
SHA256 1277dfff73130b2e106bf3dd347adb3c5f6c4340882289d88f31240da92cbd6d
MD5 24f301f860635d9bcb6e4b54736e0c99
BLAKE2b-256 790cd0eaa9380189a292121acab65199ac95b9209b45006ad8aa5266abd36943

See more details on using hashes here.

File details

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

File metadata

  • Download URL: backports.csv-1.0.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for backports.csv-1.0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 21f6e09bab589e6c1f877edbc40277b65e626262a86e69a70137db714eaac5ce
MD5 10fcdac4ee129397d1de32ac232c86b1
BLAKE2b-256 8e26a6bd68f13e0f38fbb643d6e497fc3462be83a0b6c4d43425c78bb51a7291

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