# EZCSV
Some utility functions to do the obvious things you want to do with CSV files.
`csv` is easy, this is EZ.
Install it: `pip install ezcsv`
Definitely works with Python 3+.
It's on it's way towards compatability with Python 2.6+.
It's hard to say anything about it difinitively because there are no tests.
Please see "Contributing" below.
## Reference
#### `read_dicts(file_path)`
Returns the data at `file_path` as a list of dicts.
- **`file_path`** `string | Path`
#### `read_lists(file_path)`
Returns the data at `file_path` as a list of lists. Ignores blank lines.
- **`file_path`** `string | Path`
Example Usage:
```
>>> from easycsv import csv_as_list
>>> filepath = 'C:\\path\\to\\file.csv'
>>> print(filepath)
C:\path\to\file.csv
>>> l = csv_as_list(filepath)
>>> print(l[0])
First,Line,Of,File,Prints,Here
```
#### `write_dicts(data, csv_path, mkdir=False, silent_fail=False, fieldnames=None, encoding='utf-8', **kwargs)`
Writes the input data to a CSV file
Always produces a Unix-style CSV file, regardless of whether on
Windows or not.
- **`data`** `list[dict]`
One dict per line. The first dict is expected to contain all of the
keys that will form the header line, unless `fieldnames` is provided.
- **`csv_path`** `string | Path`
Should have a .csv extension. `mkdir` will malfunction if it doesn't.
- **`mkdir`** `bool`
If true, creates the directory tree leading up to `csv_path`, ignoring
if directories already exist. Default: `False`
- **`silent_fail`**: `bool`
If `true`, causes the method to do nothing if `data` happens
to be empty. Default: `False`
- **`fieldnames`**: `list[str]`
If set, provides the list of field names to be passed to `csv.DictWriter`.
These are written as the header, regardless of what keys are present in
the first dict in `data`. Default: `None`
- **`encoding`**: `str`
The encoding to write with. Default: 'utf-8'
- **`kwargs`**: `dict`
Passed on to `csv.DictWriter`. Cannot include `fieldnames`.
#### `write_lists(data, csv_path, mkdir=False)`
Writes the input data to a CSV file
Always produces a Unix-style CSV file, regardless of whether on
Windows or not.
- **`data`** `list[list]`
- **`csv_path`** `string | Path`
Should have a .csv extension. `mkdir` will malfunction if it doesn't.
- **`mkdir`** `bool`
If true, creates the directory tree leading up to `csv_path`, ignoring
if directories already exist.
## Contributing
This could really use some tests!
Feel free to fork and open a pull request. Please, one pull request per
functional change.
Some utility functions to do the obvious things you want to do with CSV files.
`csv` is easy, this is EZ.
Install it: `pip install ezcsv`
Definitely works with Python 3+.
It's on it's way towards compatability with Python 2.6+.
It's hard to say anything about it difinitively because there are no tests.
Please see "Contributing" below.
## Reference
#### `read_dicts(file_path)`
Returns the data at `file_path` as a list of dicts.
- **`file_path`** `string | Path`
#### `read_lists(file_path)`
Returns the data at `file_path` as a list of lists. Ignores blank lines.
- **`file_path`** `string | Path`
Example Usage:
```
>>> from easycsv import csv_as_list
>>> filepath = 'C:\\path\\to\\file.csv'
>>> print(filepath)
C:\path\to\file.csv
>>> l = csv_as_list(filepath)
>>> print(l[0])
First,Line,Of,File,Prints,Here
```
#### `write_dicts(data, csv_path, mkdir=False, silent_fail=False, fieldnames=None, encoding='utf-8', **kwargs)`
Writes the input data to a CSV file
Always produces a Unix-style CSV file, regardless of whether on
Windows or not.
- **`data`** `list[dict]`
One dict per line. The first dict is expected to contain all of the
keys that will form the header line, unless `fieldnames` is provided.
- **`csv_path`** `string | Path`
Should have a .csv extension. `mkdir` will malfunction if it doesn't.
- **`mkdir`** `bool`
If true, creates the directory tree leading up to `csv_path`, ignoring
if directories already exist. Default: `False`
- **`silent_fail`**: `bool`
If `true`, causes the method to do nothing if `data` happens
to be empty. Default: `False`
- **`fieldnames`**: `list[str]`
If set, provides the list of field names to be passed to `csv.DictWriter`.
These are written as the header, regardless of what keys are present in
the first dict in `data`. Default: `None`
- **`encoding`**: `str`
The encoding to write with. Default: 'utf-8'
- **`kwargs`**: `dict`
Passed on to `csv.DictWriter`. Cannot include `fieldnames`.
#### `write_lists(data, csv_path, mkdir=False)`
Writes the input data to a CSV file
Always produces a Unix-style CSV file, regardless of whether on
Windows or not.
- **`data`** `list[list]`
- **`csv_path`** `string | Path`
Should have a .csv extension. `mkdir` will malfunction if it doesn't.
- **`mkdir`** `bool`
If true, creates the directory tree leading up to `csv_path`, ignoring
if directories already exist.
## Contributing
This could really use some tests!
Feel free to fork and open a pull request. Please, one pull request per
functional change.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ezcsv-0.3.tar.gz
(3.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ezcsv-0.3-py3-none-any.whl
(5.4 kB
view details)
File details
Details for the file ezcsv-0.3.tar.gz.
File metadata
- Download URL: ezcsv-0.3.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28210d0bb9fe7308b9592ae4cf1712a05138d27dc43aa082e36e3bad6ef81574
|
|
| MD5 |
7039417149afd4d61c44be2283711070
|
|
| BLAKE2b-256 |
0ed6f79124af4e9cf2a67fcfae09f640e2307a954d72de9eacc4eba1ea2d2610
|
File details
Details for the file ezcsv-0.3-py3-none-any.whl.
File metadata
- Download URL: ezcsv-0.3-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03943f6ebd78d52ff8ce8cec9d9cd58049a70ff6ace9a2337d88176bb351bb75
|
|
| MD5 |
5049ada24b0d266d165003f86ff08ee8
|
|
| BLAKE2b-256 |
e733c7901276cca869609b595a08c4f84cc627bfe6bede4bce5e8f85df0abded
|