Read/write lists and maps (two dimensional lists) from/to files.
Project description
# ListIO
Read/write lists and maps (two dimensional lists) from/to files.
- Lists are stored as plain text files with one list item per line.
- Maps (two dimensional lists) are stored as CSV.
When reading a list or map, lines starting with a hash sign (`#`) are considered
to be comments and therefore ignored.
## Installation
Install ListIO using pip:
```
pip install listio
```
## Usage
### Lists
#### Writing
```python
import listio
listio.write_list(
'mylist.txt',
['foo', 'bar', 'baz']
)
```
mylist.txt now contains:
```
foo
bar
baz
```
#### Reading
mylist.txt:
```
First item
second item
foo
# this is a comment
bar
```
Read `mylist.txt` as an iterator:
```python
>>> import listio
>>> mylist = listio.read_list('mylist.txt')
>>> list(mylist)
['First item', 'second item', 'foo', 'bar']
```
### Maps
#### Writing
```python
import listio
listio.write_map(
'mymap.csv,
[['foo bar', 'baz', 'x'], [1, 2, 3]]
)
```
mymap.csv now contains:
```
foo bar;baz;x
1;2;3
```
The default CSV delimiter is `;` and lineterminator `\n`. You can change this:
``` python
listio.write_map(
'mymap.csv,
[['foo bar', 'baz', 'x'], [1, 2, 3]],
delimiter=',',
lineterminator='\r\n'
)
```
### Reading
mymap.csv:
```csv
First column;"second column";3
# this is a comment
"next;item,";foo;bar
```
Read `mymap.csv` as an iterator:
```python
>>> import listio
>>> mymap = listio.read_map('mymap.csv')
>>> list(mymap)
[['First column', 'second column', '3'], ['next;item,', 'foo', 'bar']]
```
The default CSV delimiter is `;` and lineterminator `\n`. You can change this:
``` python
>>> listio.read_map('mymap.csv', delimiter=',', lineterminator='\r\n')
```
## Examples
See [tests/test_listio.py](tests/test_listio.py) for more usage examples.
## Contributing
See [NOTICE](./NOTICE) and [LICENSE](./LICENSE) for license information.
Read/write lists and maps (two dimensional lists) from/to files.
- Lists are stored as plain text files with one list item per line.
- Maps (two dimensional lists) are stored as CSV.
When reading a list or map, lines starting with a hash sign (`#`) are considered
to be comments and therefore ignored.
## Installation
Install ListIO using pip:
```
pip install listio
```
## Usage
### Lists
#### Writing
```python
import listio
listio.write_list(
'mylist.txt',
['foo', 'bar', 'baz']
)
```
mylist.txt now contains:
```
foo
bar
baz
```
#### Reading
mylist.txt:
```
First item
second item
foo
# this is a comment
bar
```
Read `mylist.txt` as an iterator:
```python
>>> import listio
>>> mylist = listio.read_list('mylist.txt')
>>> list(mylist)
['First item', 'second item', 'foo', 'bar']
```
### Maps
#### Writing
```python
import listio
listio.write_map(
'mymap.csv,
[['foo bar', 'baz', 'x'], [1, 2, 3]]
)
```
mymap.csv now contains:
```
foo bar;baz;x
1;2;3
```
The default CSV delimiter is `;` and lineterminator `\n`. You can change this:
``` python
listio.write_map(
'mymap.csv,
[['foo bar', 'baz', 'x'], [1, 2, 3]],
delimiter=',',
lineterminator='\r\n'
)
```
### Reading
mymap.csv:
```csv
First column;"second column";3
# this is a comment
"next;item,";foo;bar
```
Read `mymap.csv` as an iterator:
```python
>>> import listio
>>> mymap = listio.read_map('mymap.csv')
>>> list(mymap)
[['First column', 'second column', '3'], ['next;item,', 'foo', 'bar']]
```
The default CSV delimiter is `;` and lineterminator `\n`. You can change this:
``` python
>>> listio.read_map('mymap.csv', delimiter=',', lineterminator='\r\n')
```
## Examples
See [tests/test_listio.py](tests/test_listio.py) for more usage examples.
## Contributing
See [NOTICE](./NOTICE) and [LICENSE](./LICENSE) for license information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
listio-1.1.0.tar.gz
(2.6 kB
view details)
File details
Details for the file listio-1.1.0.tar.gz.
File metadata
- Download URL: listio-1.1.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65a7fffab97ee8f49c00e0e11e83b2a962aaf249896758a908cfcbb9ec423d4b
|
|
| MD5 |
24d495530df9d811ebea03e3cf68ca68
|
|
| BLAKE2b-256 |
5c03d2054768a8290ccf36f364eb49c3cea77b6b127140575615250e7843ab89
|