Python tail is a simple implementation of GNU tail and head.
It provides 3 main functions that can be performed on any file-like object that supports seek() and tell().
tail - read lines from the end of a file
head - read lines from the top of a file
follow - read lines as a file grows
It also comes with pytail, a command line version offering the same functionality as GNU tail. This can be particularly useful on Windows systems that have no tail equivalent.
Installation
Install with pip or easy_install.
pip install tailer
Examples
import tailer
f = open('test.txt', 'w')
for i in range(11):
f.write('Line %d\\n' % (i + 1))
f.close()
Tail
# Get the last 3 lines of the file
tailer.tail(open('test.txt'), 3)
# ['Line 9', 'Line 10', 'Line 11']
Head
# Get the first 3 lines of the file
tailer.head(open('test.txt'), 3)
# ['Line 1', 'Line 2', 'Line 3']
Follow
# Follow the file as it grows
for line in tailer.follow(open('test.txt')):
print line
Running Tests
Tailer currently only has doctests.
Run tests with nose:
nosetests --with-doctest src/tailer
Run tests with doctest:
python -m doctest -v src/tailer/__init__.py
Metadata
Release files for tailer3 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tailer3-0.3.tar.gz | 9.0 kB | Details |
Release files / tailer3-0.3.tar.gz
| Download URL | tailer3-0.3.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b85b93a859b88bec4b1a55495d6f41e0c717d3ddfac54dc8711a50c9470fcc72
|
|
BLAKE2b-256 checksum How to use checksums |
f61a08234ccafdf0f580d97f8321e318e5ccf1b4559e74e02ae33bde8b7ed5d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |