python tail是gnu tail和head的简单实现。

tailer的Python项目详细描述


Build Status

Python tail是GNU tail和head的简单实现

它提供了3个主要函数,可以在任何支持seek()tell()的类文件对象上执行。

  • tail-从文件末尾读取行
  • head-从文件顶部读取行
  • follow-随着文件的增长读取行

它还附带了pytail,这是一个命令行版本,提供与GNU tail相同的功能这在没有尾部等价物的windows系统上特别有用。

安装

使用pipeasy_install安装。

pip install tailer

示例

import tailer
f = open('test.txt', 'w')
for i in range(11):
    f.write('Line %d\\n' % (i + 1))
f.close()

尾部

# Get the last 3 lines of the file
tailer.tail(open('test.txt'), 3)
# ['Line 9', 'Line 10', 'Line 11']

跟随

# Follow the file as it grows
for line in tailer.follow(open('test.txt')):
    print line

运行测试

泰勒目前只有博士学位。

用鼻子进行测试:

nosetests --with-doctest src/tailer

使用doctest运行测试:

python -m doctest -v src/tailer/__init__.py

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
c#Java Tcp服务器和。Net Tcp客户端的发送和接收问题   安卓应用程序上的java标记地理位置,其位置位于我周围5Km半径范围内。   向java添加对话框并检索html文件   当eclipse甚至无法打开时,java会在eclipse中更改不兼容的JVM   java中同一jframe中的jlabel和paintComponent   基于另一数组排序的java排序   java AADSTS7000012:该补助金是为另一个租户获得的   java在JSF中使用foreach循环   java如何通过maven为运行junit测试创建运行配置?   java Selenium webDriver不稳定错误堆栈跟踪   java有没有办法创建以键为大写的JSON对象?