Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Yelrose/linecache_light
A python package that can fast random access any lines in a large file without high memory cost.
https://github.com/Yelrose/linecache_light
Last synced: 3 months ago
JSON representation
A python package that can fast random access any lines in a large file without high memory cost.
- Host: GitHub
- URL: https://github.com/Yelrose/linecache_light
- Owner: Yelrose
- License: mit
- Created: 2017-03-14T02:38:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-19T05:08:00.000Z (over 2 years ago)
- Last Synced: 2024-07-14T02:44:03.881Z (4 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 18
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# linecache_light
A python package that can fast random access any lines in a large file without high memory cost.## Usage
It's avaiable to install linecache_light throught pip.
```
pip install linecache_light
```The basic usage is followed:
```
from linecache_light import LinceCache
linecache = LineCache('large_file.txt', cache_suffix='.cache')
# This will create a cache file with suffix in your file location
# Noticing it may cost a long time to cache the file since the LineCache will scan through the document.
# If the cache file has already existed, it will reload the cache file in a much short time without scan through the document again.
# Check the total number of lines
print len(linecache)
# Access the lines by line index
print linecache[5]
# Access the lines by slice
print linecache[3:5]
print linecache[-1]
# Access the lines by a iterable list of index
print linecache[[3,2,1,5]]
```