csvprint
A command-line utility for pretty printing csv files and converting to other formats.
Installation
If Python 3 with the package manager pip is installed, doing pip3 install csvprint in your terminal should do the trick.
Development installation
With pipenv installed.
- Clone this repo
- Do
pipenv install pipenv shellpip install -e .
Usage
csvprint [filename] prints a formatted table if filename is a comma separated file.
» cat imdb.csv
Title,Release Year,Estimated Budget
Shawshank Redemption,1994,$25 000 000
The Godfather,1972,$6 000 000
The Godfather: Part II,1974,$13 000 000
The Dark Knight,2008,$185 000 000
12 Angry Men,1957,$350 000
» csvprint imdb.csv
Title Release Year Estimated Budget
Shawshank Redemption 1994 $25 000 000
The Godfather 1972 $6 000 000
The Godfather: Part II 1974 $13 000 000
The Dark Knight 2008 $185 000 000
12 Angry Men 1957 $350 000
You can also pipe into csvprint:
» cat imdb.csv | csvprint
Title Release Year Estimated Budget
Shawshank Redemption 1994 $25 000 000
The Godfather 1972 $6 000 000
The Godfather: Part II 1974 $13 000 000
The Dark Knight 2008 $185 000 000
12 Angry Men 1957 $350 000
Options
| Command | Result |
|---|---|
-a |
specify alignment (left or right) - see examples below |
-c |
specify which columns to print |
-h |
print help message |
--markdown |
print as markdown |
--latex |
print as latex table |
--numeric [c1:d1] [c2:d2] ... |
specify decimal numbers for chosen numeric columns (c for column, d for digits) |
--header |
add header decoration around the first line |
-s 'char' |
file is delimited by char (instead of comma), tab for tab |
-p [n] |
add a padding of n spaces for each column, on both sides |
-d [string] |
specify the string to separate columns |
Alignment example
There are three options for specifying alignment. One can use l or r for aligning all cells to the left or right, respectively. One can also specify a distinct alignment option for each column. Then the number of options will need to match the number of columns.
» csvprint imdb.csv -a l r r
Title Release Year Estimated Budget
Shawshank Redemption 1994 $25 000 000
The Godfather 1972 $6 000 000
The Godfather: Part II 1974 $13 000 000
The Dark Knight 2008 $185 000 000
12 Angry Men 1957 $350 000
Markdown example
Markdown output also supports left and right alignment.
» csvprint examples/imdb.csv --markdown -a l r r
Title | Release Year | Estimated Budget
:----------------------|-------------:|----------------:
Shawshank Redemption | 1994 | $25 000 000
The Godfather | 1972 | $6 000 000
The Godfather: Part II | 1974 | $13 000 000
The Dark Knight | 2008 | $185 000 000
12 Angry Men | 1957 | $350 000
When rendered as HTML, this looks like
| Title | Release Year | Estimated Budget |
|---|---|---|
| Shawshank Redemption | 1994 | $25 000 000 |
| The Godfather | 1972 | $6 000 000 |
| The Godfather: Part II | 1974 | $13 000 000 |
| The Dark Knight | 2008 | $185 000 000 |
| 12 Angry Men | 1957 | $350 000 |
Numeric example
» csvprint examples/numeric.csv
measure1 measure2
1.2323 9000
1.299 9000001
» csvprint examples/numeric.csv --numeric 1:1 2:1
measure1 measure2
1.2 9000.0
1.3 9000001.0
Testing
Run pytest while in the root directory of this repository.
Metadata
Release files for csvprint 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| csvprint-0.7.0.tar.gz | 7.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| csvprint-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.7 kB
Release files / csvprint-0.7.0.tar.gz
| Download URL | csvprint-0.7.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a594d2a835131f7da34f45d2874645f6e4df2017026f8acdb2dd584a93cc5247
|
|
BLAKE2b-256 checksum How to use checksums |
c569de17a433a3241435c9d72416b376a47a8dbb5ba920c0739ce84b7c576f73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.4 Darwin/19.0.0
|
Release files / csvprint-0.7.0-py3-none-any.whl
| Download URL | csvprint-0.7.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e0b3fb84d0d63a6cb6291051a209df3c8cdf63bfb13e1e2d8338c449923c60f
|
|
BLAKE2b-256 checksum How to use checksums |
ef9df74d81c4a78381d0438347aa926a5b72c3bb53ba4aa47b51e91c4bb6ae3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.4 Darwin/19.0.0
|