A custom CSV reader implementation with direct file access
Project description
csv-position-reader
A custom CSV reader implementation with direct file access
The default builtin Python csv
lib uses an 8KB
read-ahead buffer on the file pointer, making fp.tell()
yield inaccurate results. This library addresses that head on, explicitly passing back the file pointer position with each row, as well as allowing for direct seeking.
References:
- https://docs.python.org/2/library/csv.html
- https://stackoverflow.com/questions/14145082/file-tell-inconsistency/14145118#14145118
- https://stackoverflow.com/questions/12109622/how-to-know-the-byte-position-of-a-row-of-a-csv-file-in-python/12110160#12110160
Usage
>>> import csv_position_reader
>>> with open('tests/data/basic.csv', 'r') as fp:
... reader = csv_position_reader.DictReader(fp)
... position, row = reader.next()
... print "position: %s" % position
... print "row: %s" % row
... reader.seek(position)
... position_new, row_new = reader.next()
... assert position == position_new
... assert row == row_new
...
position: 26
row: {'city': 'Atlanta', 'favorite_color': 'black', 'name': 'Sam'}
Why? / Who Cares?
Because after poring through a CSV one time, you can now build a dictionary/cache of where each row lives for future O(1)
access! You're now a stone's throw away from a CSV-driven database!
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
Built Distribution
File details
Details for the file csv-position-reader-0.1.0.tar.gz
.
File metadata
- Download URL: csv-position-reader-0.1.0.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4737871b2b23b3f88b5e3f396d1b41ece7d7477c8aa1f44398cbb660b57ca992 |
|
MD5 | e0c7117666eceb9da9ef880fb23cc0a2 |
|
BLAKE2b-256 | e788895c475df026c17db44fd4b9d5c773123844c58e6395f0e99f713e72d124 |
File details
Details for the file csv_position_reader-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: csv_position_reader-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e07e479946b0f9fc7a9ad227653abd12f89f5e2f6973d91624c28b4df542afd |
|
MD5 | 8c272fb0dd865941233ee818a9ccddac |
|
BLAKE2b-256 | 254b2f1a0f5941263573a44ab956358417f54e6c1b3f6dc30f043d3db042470e |