Skip to content

Commit 74c3667

Browse files
committed
updated readme
1 parent 541d875 commit 74c3667

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Random Access File Reader
77
88
Installation
99
============
10-
``pip install git+https://github.com/jegesh/python-random-access-file-reader.git#egg=randomAccessReader``
10+
``pip install random-access-file-reader``
1111

1212
Usage
1313
=====
@@ -20,6 +20,8 @@ Usage
2020
2121
::
2222

23+
from randomAccessReader import RandomAccessReader
24+
2325
reader = RandomAccessReader('~/myfile.txt')
2426

2527
# single line
@@ -31,10 +33,12 @@ Usage
3133
for l in lines:
3234
print l
3335

36+
|
3437
| Csv example:
3538
3639
::
3740

41+
from randomAccessReader import CsvRandomAccessReader
3842
reader = CsvRandomAccessReader('~/myfile.csv')
3943

4044
# single line

randomAccessReader/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ def _get_line_values(self, line):
9999
dialect = self.MyDialect(self._endline, self._quotechar, self._delimiter)
100100
b = StringIO.StringIO(line)
101101
r = csv.reader(b, dialect)
102-
return tuple(r.next())
102+
values = tuple(r.next())
103+
if len(self._headers) != len(values):
104+
raise ValueError("Corrupt csv - header and row have different lengths")
105+
return values
106+
103107

104108
def get_line_dicts(self, line_number, amount=1):
105109
"""
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Metadata-Version: 1.1
2+
Name: random-access-file-reader
3+
Version: 0.2.1
4+
Summary: A python random access file reader
5+
Home-page: https://github.com/jegesh/python-random-access-file-reader
6+
Author: Yaakov Gesher
7+
Author-email: [email protected]
8+
License: Apache Software License
9+
Description: Random Access File Reader
10+
-------------------------
11+
12+
| This is a small library that allows for reading any given line in a file without having to read all the lines before it
13+
or load the entire file into memory. Only the line indexes and lengths are held in memory, which enables random
14+
access even on very large files at a very minuscule memory cost.
15+
16+
Installation
17+
============
18+
``pip install random-access-file-reader``
19+
20+
Usage
21+
=====
22+
23+
| Usage is very straightforward, and standard csv line endings (newline character), value delimiter (comma), and
24+
quotation character (double quote) are the defaults. These can be changed in the constructor.
25+
|
26+
| The ``get_line()`` and ``get_line_dicts()`` methods return a list of rows.
27+
| Plain text file example:
28+
29+
::
30+
31+
from randomAccessReader import RandomAccessReader
32+
33+
reader = RandomAccessReader('~/myfile.txt')
34+
35+
# single line
36+
line = reader.get_lines(2)[0]
37+
print line
38+
39+
# multiple lines
40+
lines = reader.get_lines(3, 3)
41+
for l in lines:
42+
print l
43+
44+
45+
| Csv example:
46+
47+
::
48+
49+
from randomAccessReader import CsvRandomAccessReader
50+
reader = CsvRandomAccessReader('~/myfile.csv')
51+
52+
# single line
53+
line = reader.get_line_dicts(5)[0]
54+
for x in line:
55+
print x + " = " line[x]
56+
57+
# multiple lines
58+
lines = reader.get_line_dicts(6, 6)
59+
for l in lines:
60+
for x in l:
61+
print x + " = " l[x]
62+
63+
Platform: UNKNOWN
64+
Classifier: Development Status :: 3 - Alpha
65+
Classifier: Intended Audience :: Developers
66+
Classifier: Topic :: Software Development :: Libraries
67+
Classifier: License :: OSI Approved :: Apache Software License
68+
Classifier: Programming Language :: Python :: 2.7
69+
Classifier: Programming Language :: Python :: 3.5
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
README.rst
2+
setup.py
3+
randomAccessReader/__init__.py
4+
random_access_file_reader.egg-info/PKG-INFO
5+
random_access_file_reader.egg-info/SOURCES.txt
6+
random_access_file_reader.egg-info/dependency_links.txt
7+
random_access_file_reader.egg-info/top_level.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
randomAccessReader

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Versions should comply with PEP440. For a discussion on single-sourcing
1616
# the version across setup.py and the project code, see
1717
# https://packaging.python.org/en/latest/single_source_version.html
18-
version='0.2.0',
18+
version='0.2.1',
1919

2020
description='A python random access file reader',
2121
long_description=long_description,

0 commit comments

Comments
 (0)