Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/greatfruitomsk/tailhead
head, tail and follow in python
https://github.com/greatfruitomsk/tailhead
head python tail
Last synced: about 2 months ago
JSON representation
head, tail and follow in python
- Host: GitHub
- URL: https://github.com/greatfruitomsk/tailhead
- Owner: GreatFruitOmsk
- License: mit
- Created: 2015-08-11T18:32:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-30T21:46:12.000Z (about 3 years ago)
- Last Synced: 2024-09-22T10:35:28.794Z (3 months ago)
- Topics: head, python, tail
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 15
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. image:: https://travis-ci.org/GreatFruitOmsk/tailhead.svg?branch=master
======
tailhead
======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 growsIt 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.
- `tailhead on GitHub `_
- `tailhead on Pypi `_Installation
============Install with ``pip`` or ``easy_install``.
::
pip install tailhead
Examples
========::
import tailhead
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
tailhead.tail(open('test.txt', 'rb'), 3)
# [b'Line 9', b'Line 10', b'Line 11']Head
----
::# Get the first 3 lines of the file
tailhead.head(open('test.txt', 'rb'), 3)
# [b'Line 1', b'Line 2', b'Line 3']# Get all lines but last 6 lines of the file
tailhead.head(open('test.txt', 'rb'), -6)
# [b'Line 1', b'Line 2', b'Line 3', b'Line 4', b'Line 5']Follow
------
::# Follow the file as it grows and handle file rotation if it occurs
import time
for line in tailhead.follow_path('test.txt'):
if line is not None:
print(line)
else:
time.sleep(1)Running Tests
=============Tailer currently only has doctests.
Run tests with nose::
nosetests --with-doctest tailhead
Run tests with doctest::
python -m doctest -v tailhead/__init__.py