Re: Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Asun Friere
On Aug 29, 9:49 am, "Deivys Ramirez" <[EMAIL PROTECTED]> wrote: > What's the "pythonic" way of reading a text file, line by line, > without throwing an exception when there's nothing to be read? > > I've been trying to map my while(!eof(fp)) mindset to the file object > Python gives me when I call

Re: Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Matimus
> fp=open(filename, 'r') > for line in fp: > # do something with line > > fp.close() Or, if you are using Python 2.5+, you can use the file context via the `with' statement. [code] from __future__ import with_statement # this line won't be needed in Python 2.6+ with open(filename, 'r') as fp

Re: Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Larry Bates
Deivys Ramirez wrote: > Hi everyone, > > I'm a Python newbie but have experience programming PHP and C so i'm > not really new to programming but new to Python. > > What's the "pythonic" way of reading a text file, line by line, > without throwing an exception when there's nothing to be read? >

Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Deivys Ramirez
Hi everyone, I'm a Python newbie but have experience programming PHP and C so i'm not really new to programming but new to Python. What's the "pythonic" way of reading a text file, line by line, without throwing an exception when there's nothing to be read? I've been trying to map my while(!eof(