#!/usr/bin/env python3 from time import sleep def tail (filename, n=0, polling=0.01): num_lines = sum(1 for line in open(filename)) f = open(filename,'r') cpt = 0 while cpt < num_lines - n : cpt += 1 next(f) try: while True: try: l = next(f) print(filename,":",l[:-1]) except: sleep(polling) except: f.close()