Skip to main content

A tiny library for handling CSV files.

Project description

incisive is a tiny library for handling CSV in Python. It’s a wrapper for the csv module.

Usage

  • You can read a csv file like this:

    >>> iris = read_csv("data/iris.csv")
    >>> iris.next()
    {'petal_length': 1.4,
     'petal_width': 0.2,
     'sepal_length': 5.1,
     'sepal_width': 3.5,
     'species': 'setosa'}

read_csv returns a generator. Note that incisive, by default, tries to guess the type of the columns.

  • Writing a CSV file can be done in two ways:

  1. with a list of dictionaries:

    >>> data = [{'name': 'Lancelot', 'actor': 'John Cleese', 'color': 'blue'},
               {'name': 'Galahad', 'actor': 'Michael Palin', 'color': 'yellow'}]
    
    >>> write_csv('bridge.csv', ('name', 'actor', 'color'), data=data)

(the keys are the field names of the CSV file.)

  1. or with just a list of rows:

    >>> rows = [('Lancelot', 'John Cleese', 'blue'),
            ('Galahad', 'Michael Palin', 'yellow')]
    
    >>> write_csv('bridge.csv', ('name', 'actor', 'color'), rows=rows)

Note that this second method requires that your field names correspond exactly to the elements of your rows.

Features

  • Simple API

  • Guess the types when it’s possible

  • Accept functions to specify the types

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

incisive-0.1.0.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file incisive-0.1.0.tar.gz.

File metadata

  • Download URL: incisive-0.1.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for incisive-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07606757ecc757bb714eddb9f349f9d030e3e7e0191b3168fea9a153778ccfb9
MD5 bfbe47fc84cb1e6c447e1064c771b44b
BLAKE2b-256 827c9d9d6c85e3d1989b55c443f1a9c9c59bca8ef0a2d63a60d217c93d32f472

See more details on using hashes here.

Supported by

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