Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

some utilities for CSV files and the like

Project Description

For when you …um have some CSV files that you need to do some things to.

About

This repository contains two scripts I wrote for someone that were never intended to be used for general use. The original scripts can be found at csvutils. I then decided to make this repo to turn those scripts into a Python package and experiment with CI and Sphinx.

Installation

This repository is installable as a Python package, although it is not currently hosted on PyPI. These installation methods are currently untested

Method 1:

$ git clone https://github.com/erszk/some_csvutils
Cloning into 'some_csvutils'...
remote: Counting objects: 8, done.
remote: Total 8 (delta 0), reused 0 (delta 0), pack-reused 8
Receiving objects: 100% (8/8), 8.41 KiB | 0 bytes/s, done.
Checking connectivity... done.

$ pip install -e some_csvutils
Obtaining file:///${HOME}/some_csvutils
Installing collected packages: some-csvutils
  Running setup.py develop for some-csvutils
Successfully installed some-csvutils-3.1

Then, updating is as simple as doing git pull origin from within the repo

Method 2:

$ pip install https://github.com/some_csvutils/zipball/master

For copy and pasting:

git clone https://github.com/erszk/some_csvutils;
pip install -e some_csvutils

Usage

The two scripts this package provides are truncheadcsv and catcsv. The former of these removes n number of lines from whatever files given to it, while the latter takes a number of files and concatenates them together removing the first line from all but one of the files and adding an extra filename field to the data file, which corresponds to the file from which the data comes.

Truncheadcsv:

usage: truncheadcsv [-hv] NUM [-d DIR] [-o | -e EXT] [[-f FILE]... | -g GLOB]

Remove unneeded headers from data files

positional arguments:
  NUM                   the number of lines to be truncated

optional arguments:
  -h, --help            show this help message and exit
  -d DIR, --dir DIR     the target directory to truncate all CSVs in
  -f FILE, --file FILE  files to truncate
  -g GLOB, --glob GLOB  glob pattern to match files [default: *.csv]
  -o, --overwrite       overwrite files without making backups
  -e EXT, --ext EXT     backup extension [default: .trc]
  -v, --version         show program's version number and exit

NOTE: glob patterns should be put in quotes; filenames listed with the -f flag
should not be relative paths if the -d flag is also enabled.

Catcsv:

usage: catcsv [-h] [-d DIR] [-o OUTPUT] [-y] [-f FILE ... | -g GLOB]
              [--nosrc | -s SEP] [-v]

strip headers and concatenate data files

optional arguments:
  -h, --help            show this help message and exit
  -d DIR, --dir DIR     the target directory for file concatenation
  -o OUTPUT, --output OUTPUT
                        output for concatenation [default: cat.csv]
  -y                    do not ask to overwrite output file
  -f FILE ..., --file FILE ...
                        files to concatenate
  -g GLOB, --glob GLOB  glob pattern to match files [default: *.csv]
  --nosrc               do not add source file field to concatenated file
  -s SEP, --sep SEP     field separator [default: ',' (comma)]
  -v, --version         show program's version number and exit

NOTE: glob patterns should be put in quotes

Dependencies

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pkg_resources as pr

try:
    mypkg = pr.working_set.by_key['some-csvutils']
    deps = [str(dep) for dep in mypkg.requires()]

    if len(deps) == 0:
        print('The standard library rules!')

except KeyError:
    print("Why haven't you installed it yet?")

Todo

  • make it possible for one/either/both utilities to write to stdout to pipe the output of one into the other
  • write more tests
  • connect to coveralls
  • connect to ReadTheDocs
  • make documentation with Sphinx
Release History

Release History

This version
History Node

3.2

History Node

3.1

History Node

3.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
some_csvutils-3.2.tar.gz (6.2 kB) Copy SHA256 Checksum SHA256 Source Dec 19, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting