Python pyinotify模块实现对文档的实时监控功能方法
2018-12-11 20:03
3359 查看
0x01 安装pyinotify
>>> pip install pyinotify >>> import pyinotify
0x02 实现对文档的试试监控功能
这个功能类似与Ubuntu里的rail -f功能,在对目标文件进行修改时,脚本可以实时监控并将新的修改打印出来。
import pyinotify import time import os class ProcessTransientFile(pyinotify.ProcessEvent): def process_IN_MODIFY(self, event): line = file.readline() if line: print line, # already has newline filename = './test.txt' file = open(filename,'r') #Find the size of the file and move to the end st_results = os.stat(filename) st_size = st_results[6] file.seek(st_size) wm = pyinotify.WatchManager() notifier = pyinotify.Notifier(wm) wm.watch_transient_file(filename, pyinotify.IN_MODIFY, ProcessTransientFile) notifier.loop()
以上这篇Python pyinotify模块实现对文档的实时监控功能方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- python实现实时监控文件的方法
- python实现实时监控文件的方法
- Python pyinotify模块实现对文档的实时监控功能
- 使用ASM4.0实现AOP的功能,监控每个方法的执行时间
- python使用pyhook监控键盘并实现切换歌曲的功能
- 这篇文章主要介绍了Python使用函数默认值实现函数静态变量的方法,是很实用的功能
- Python使用pylab库实现画线功能的方法详解
- python使用pyhook监控键盘并实现切换歌曲的功能
- Python简单实现enum功能的方法
- Python WXPY实现微信监控报警功能的代码
- 使用Python通过win32 COM实现Word文档的写入与保存方法
- python也能实现类初始化方法需求更改的功能
- 用python 类方法,实现银行卡类功能查询等?
- python实现监控linux性能及进程消耗性能的方法
- ArcGIS API for Flex实现的实时监控功能
- 实现对文件的实时监控--使用Inotify方法
- Python 使用 pylab 库实现画线功能的方法详解
- Python实现Logger打印功能的方法详解
- Python基于jieba库进行简单分词及词云功能实现方法
- 零基础新手的Python入门实战宝典(四) —— 如何实现一个想要的功能?(方法或函数)