- Notifications
You must be signed in to change notification settings - Fork6
jegesh/python-random-access-file-reader
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a small library that allows for reading any given line in a file without having to read all the lines before itor load the entire file into memory. Only the line indexes and lengths are held in memory, which enables randomaccess even on very large files for a very minuscule memory cost.
pip install random-access-file-reader
Usage is very straightforward, and standard csv line endings (newline character), value delimiter (comma), andquotation character (double quote) are the defaults. These can be changed in the constructor.
The
get_line() andget_line_dicts() methods return a list of rows.Plain text file example:
from randomAccessReader import RandomAccessReaderreader = RandomAccessReader('~/myfile.txt')# single lineline = reader.get_lines(2)[0]print line# multiple lineslines = reader.get_lines(3, 3)for l in lines: print lOptional arguments in the constructor:
endline_character- self-explanatory (default is endline character\n)ignore_blank_lines- if set toTrue, blank lines in the file will not be read or indexed (default isFalse)
Csv example:
from randomAccessReader import CsvRandomAccessReaderreader = CsvRandomAccessReader('~/myfile.csv')# single lineline = reader.get_line_dicts(5)[0]for x in line: print x + " = " line[x]# multiple lineslines = reader.get_line_dicts(6, 6)for l in lines: for x in l: print x + " = " l[x]Optional arguments in the constructor:
endline_character- self-explanatory (default is endline character\n)ignore_blank_lines- if set toTrue, blank lines in the file will not be read or indexed (default isTrue)values_delimiter- character used by the csv to separate values within a line (default is,)quotechar- character used by the csv to surround values that contain the value delimiting character (default is")ignore_corrupt- if set toTrue, lines with an invalid length will return blank instead of raising an exception (default isFalse)
About
Low memory usage random access reader for csv and general files
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.