Skip to main content

A Simple line generator from tail of file

Project description

readtail

Simple Description

  • A simplest generator function written in pure python
  • Seek from the tail of the file

Install

pip install tailread

Useage

import tailread as tail

# consuming tails one by one
  lines = tail.readlines('access.log')

  # take tail of one line
  line = next(lines)
  print(line)
# b'line 10/r/n'

  # next...
  line = next(lines)
  print(line)
# b'line 9/r/n'


# When passing a fileobject, The file must be opened in bytes mode.
with open('access.log', 'rb'): as fp:
    for line in tail.readlines(fp):
        print(line)
        if 'some string' in line:
            break
        

# or from file path
for line in tail.readlines('access.log'):
    print(line)
      if 'some string' in line:
          break

# b'line 10\r\n'
# b'line 9\r\n'
# b'line 8\r\n'
# b'line 7\r\n'
# ....
# decoding lines from encoding info
for line in tail.readlines('access.log', encoding='utf-8', errors='ignore'):
    print(line)

# line 10

# line 9

# line 8

# line 7

# ....

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

tailread-1.0.1.tar.gz (2.7 kB view details)

Uploaded Source

File details

Details for the file tailread-1.0.1.tar.gz.

File metadata

  • Download URL: tailread-1.0.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for tailread-1.0.1.tar.gz
Algorithm Hash digest
SHA256 25c4b568f06cfad8071a050257a24ee2efd8a5e03513aaf1eec104096d031b5f
MD5 fc0d155e88f2124ce1670d9d8147d0b2
BLAKE2b-256 cae04c58b3bc8cf59542da07d0e9abdfd258340a08d706c8fbbb26e7915b81b9

See more details on using hashes here.

Supported by

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