New to Python - Easy way to open a text file

kyosohma at gmail.com kyosohma at gmail.com
Fri Mar 30 15:28:13 EDT 2007


On Mar 30, 11:39 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> In <1175270675.296617.83... at e65g2000hsc.googlegroups.com>, kyosohma wrote:
> > I'm not familiar with ezt formats, however reading a text file is a
> > breeze.
>
> This sentence doesn't match the code that follow.  It's really simpler
> than that ``while`` loop.
>
> > f = open(r'pathToFile')
> > while True:
> >    line = f.readline()
> >    if not line: break
> >    # do something with the line of text such as print it.
>
> > f.close()
>
> f = open(r'pathToFile)
> for line in f:
>     # do something with the line of text such as print it.
> f.close()
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Yes, the "while" is lame, I admit it. But sometimes you just gotta go
old school!

Mike




More information about the Python-list mailing list