random-readline
Randomized fast readline for large text files.
Install
pip install random_readline
Usage
from random_readline import readline
# lines are shuffled by default.
n_lines, read = readline("text.txt")
for line in read():
print(line)
Sequencial read
from random_readline import readline
# lines are not shuffled as it is.
n_lines, read = readline("text.txt", shuffle=False)
for line in read():
print(line)
Gzipped file
import gzip
from random_readline import readline
n_lines, read = readline("text.txt.gz", opener=gzip.open)
for line in read():
print(line)
Control the frequency of seeking
Since random seeking can be very slow with gzipped files, the readline function has an option chunk_size to control the frequency of seeking.
This value is set to 1 by default, which means that a seeking is performed every single line to read the entire file completely at random.
Increasing the value of chunk_size will reduce the frequency with which seekings are performed, thus improving performance in exchange for randomness.
import gzip
from random_readline import readline
# lines will be randomized by every 100 lines
n_lines, read = readline("text.txt.gz", opener=gzip.open, chunk_size=100)
for line in read():
print(line)
Release files for random-readline 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| random_readline-0.1.0.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| random_readline-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / random_readline-0.1.0.tar.gz
| Download URL | random_readline-0.1.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7957a6f1f32c150477cfa8ba7242f62eaeb6896dbcee576cde797581d12a28a
|
|
BLAKE2b-256 checksum How to use checksums |
e45497e5c1864c6e17f4421f432c4a7d8915de243a50e3e1c2e7ab67cc780060
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.9
|
Release files / random_readline-0.1.0-py3-none-any.whl
| Download URL | random_readline-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8806ca797168a7e998e03584de7e6ac3deb3fc600fe7fd6d522275fd03b7c4e1
|
|
BLAKE2b-256 checksum How to use checksums |
e5122ac205c2539c0c2c9d2ad3f083288d2aaf19cebe221d46c8a2f6c962dcb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.9
|