Skip to main content

Memory efficient way of reading files line-by-line from the end of file

Project description

file_read_backwards

https://img.shields.io/pypi/v/file_read_backwards.svg https://img.shields.io/travis/RobinNil/file_read_backwards.svg?branch=master Documentation Status Updates

Memory efficient way of reading files line-by-line from the end of file

Features

This package is for reading file backward line by line as unicode in a memory efficient manner for both Python 2.7 and Python 3.

It currently supports ascii, latin-1, and utf-8 encodings.

It supports “\r”, “\r\n”, and “\n” as new lines.

Usage Examples

An example of using file_read_backwards for python2.7:

#!/usr/bin/env python2.7

from file_read_backwards import FileReadBackwards

with FileReadBackwards("/tmp/file", encoding="utf-8") as frb:

    # getting lines by lines starting from the last line up
    for l in frb:
        print l

Another example using python3.3:

from file_read_backwards import FileReadBackwards

with FileReadBackwards("/tmp/file", encoding="utf-8") as frb:

    # getting lines by lines starting from the last line up
    for l in frb:
        print(l)

Another way to consume the file is via readline(), in python3.3:

from file_read_backwards import FileReadBackwards

with FileReadBackwards("/tmp/file", encoding="utf-8") as frb:

    while True:
        l = frb.readline()
        if not l:
            break
        print(l, end="")

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

1.0.0 (2016-12-18)

  • First release on PyPI.

1.1.0 (2016-12-31)

  • Added support for “latin-1”.

  • Marked the package “Production/Stable”.

1.1.1 (2017-01-09)

  • Updated README.rst for more clarity around encoding support and Python 2.7 and 3 support.

1.1.2 (2017-01-11)

  • Documentation re-arrangement. Usage examples are now in README.rst

  • Minor refactoring

1.2.0 (2017-09-01)

  • Include context manager style as it provides cleaner/automatic close functionality

1.2.1 (2017-09-02)

  • Made doc strings consistent to Google style and some code linting

1.2.2 (2017-11-19)

  • Re-release of 1.2.1 for ease of updating pypi page for updated travis & pyup.

2.0.0 (2018-03-23)

Mimicing Python file object behavior.

  • FileReadBackwards no longer creates multiple iterators (a change of behavior from 1.x.y version)

  • Adding readline() function retuns one line at a time with a trailing new line and empty string when it reaches end of file. The fine print: the trailing new line will be os.linesep (rather than whichever new line type in the file).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

file_read_backwards-2.0.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

file_read_backwards-2.0.0-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file file_read_backwards-2.0.0.tar.gz.

File metadata

File hashes

Hashes for file_read_backwards-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fd50d9089b412147ea3c6027e2ad905f977002db2918cf315d64eed23d6d6eb8
MD5 d773346099cb39f0e8e873b98825c2d5
BLAKE2b-256 917d70e25cf8d8d181f2bf87da51db3eeeb984e0cb24dbb31ecbf7670727c306

See more details on using hashes here.

File details

Details for the file file_read_backwards-2.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for file_read_backwards-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 78684aafc0471e9e0f62a8662361bfaf70ade3d38333d7f166fd8024a028b1d1
MD5 65e60313040663e5b14e150d29029232
BLAKE2b-256 53ccd015aacff2ae5566e81379b2146674c6bf364c50d562add9ae292a9284dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page