tail -f en Python
[ Nouvelle discussion
| Répondre au groupe
|
fr.comp.lang.python ]
Sujet: tail -f en Python
De: artyp...@gmail.com (Salvatore DI DI0)
Groupes: fr.comp.lang.python
Organisation: les newsgroups par Orange
Date: 15. May 2008, 20:02:22
|
Hello La communauté,
Voici une application très concrète des
générateurs en Python
[code]
import time
def follow(thefile):
thefile.seek(0,2) # Go to the end of the file
while True:
line = thefile.readline()
if not line:
time.sleep(0.1) # Sleep briefly
continue
yield line
logfile = open("access-log")
loglines = follow(logfile)
for line in loglines:
print line,
[/code]
Source : http://www.dabeaz.com/generators/Generators.pdf
Cordialement
Salvatore

|
 cette fonctionnalité est reservée aux membres ayant une session active !
|