looping through a file

sismex01 at hebmex.com sismex01 at hebmex.com
Fri Jul 25 16:46:13 EDT 2003


> From: Bruno Desthuilliers [mailto:bdesth.nospam at removeme.free.fr] 
> Sent: Viernes, 25 de Julio de 2003 03:25 p.m.
> 
> [...snip...]
>
> No, but there are better ways to do it in Python :
> 
> try:
>      thefile = file(filename)
> except IOError:
>      doWhatEverWithException()
> 
> for line in thefile.readlines():
>      doWhatEverWithTheLine()
>

And even better ways:

try:
    thefile = file(filename)
except IOError:
    doWhatEverWithException()

for line in thefile:
    doWhatEverWithTheLine(line)


files have iterators now. :-)

-gustavo



Advertencia:La informacion contenida en este mensaje es confidencial y
restringida, por lo tanto esta destinada unicamente para el uso de la
persona arriba indicada, se le notifica que esta prohibida la difusion de
este mensaje. Si ha recibido este mensaje por error, o si hay problemas en
la transmision, favor de comunicarse con el remitente. Gracias.





More information about the Python-list mailing list