How to do this in Python?

afriere at yahoo.co.uk afriere at yahoo.co.uk
Wed Mar 18 20:27:13 EDT 2009


On Mar 18, 3:05 pm, Grant Edwards <gra... at visi.com> wrote:
> {snip] ... If it
> only going to be used once, then just do the usual thing:
>
> f = open(...)
> while True:
>    buf = f.read()
>    if not buf: break
>    # whatever.
> f.close()

+1

That's the canonical way (maybe using "with ... as" nowadays).  Surely
everything else is simply overkill, (or unwarranted cleverness) here.
In any case this is what most practising pythonista would comprehend
instantly.




More information about the Python-list mailing list