No Description

Jakub Valenta 8f55a18693 setup: Bump minor version to 1.1.0 3 months ago
listio c6adc52d91 Switch from unicodecsv to backports.csv 3 months ago
tests 3edc81bc8a tests: Update and test custom delimiters etc 3 months ago
.gitignore 8c9e84e509 gitignore: Ignore also venv2/ 3 months ago
LICENSE 80ac6dfb5b Initial commit 2 years ago
NOTICE 80ac6dfb5b Initial commit 2 years ago
README.md d5c58389f1 listio: Allow custom CSV delimiter, lineterminator 3 months ago
requirements.txt c6adc52d91 Switch from unicodecsv to backports.csv 3 months ago
setup.py 8f55a18693 setup: Bump minor version to 1.1.0 3 months ago
tox.ini 46ef5ec461 tox: Add, test and lint with tox 10 months ago

README.md

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

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:

>>> import listio
>>> mylist = listio.read_list('mylist.txt')
>>> list(mylist)
['First item', 'second item', 'foo', 'bar']

Maps

Writing

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:

listio.write_map(
    'mymap.csv,
    [['foo bar', 'baz', 'x'], [1, 2, 3]],
    delimiter=',',
    lineterminator='\r\n'
)

Reading

mymap.csv:

First column;"second column";3
# this is a comment
"next;item,";foo;bar

Read mymap.csv as an iterator:

>>> 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:

>>> listio.read_map('mymap.csv', delimiter=',', lineterminator='\r\n')

Examples

See tests/test_listio.py for more usage examples.

Contributing

See NOTICE and LICENSE for license information.