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
> 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
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?
>
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(