Last active 1728400902

une lib pour le suivie de l'evolution d'un fichier

Revision 77220c32690479c68cd8eb84cac9fb8e8b214853

libtail.py Raw
1#!/usr/bin/env python3
2
3from time import sleep
4
5def tail (filename, n=0, polling=0.01):
6 num_lines = sum(1 for line in open(filename))
7 f = open(filename,'r')
8 cpt = 0
9 while cpt < num_lines - n :
10 cpt += 1
11 next(f)
12
13 try:
14 while True:
15 try:
16 l = next(f)
17 print(filename,":",l[:-1])
18 except:
19 sleep(polling)
20 except:
21 f.close()
22
tail.py Raw
1#!/usr/bin/env python3
2
3from libtail import tail
4from sys import argv
5
6if len(argv) != 2:
7 print("""utilisation:
8%s FICHIER"""%argv[0])
9 exit(1)
10tail(argv[1])
11