Giter Club home page Giter Club logo

backports.csv's Introduction

backports.csv: Backport of Python 3's csv module

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 is safe to specify newline='', since the csv module does its own (universal) newline handling.

backports.csv's People

Contributors

dmiro avatar gitter-badger avatar jayvdb avatar mpeteuil avatar ryanhiebert avatar sergiuser1 avatar therg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.