On Thu, Jan 14, 2010 at 12:05 AM, Alan Gauld <alan.ga...@btinternet.com> wrote:
>
> I prefer the next() approach.

Rightfully so. IMO, The while loop with readline is basically the C
version of that, for the poor people who don't have iterators.

> But a third option is to use a split and apply it to the whole file as
> a string thereby breaking the file into as many chunks as start with
> a line containing 'NEW'...
>
> data = open(....).read()
> for chunk in data.split('NEW'):
>    for line in chunk.split('\n'):  # create lines out of the chunks - you
> may not need this
>         # process lines till done
>
> Just a thought.
>

Probably the simplest option by far. Disadvantage is you'll have to
load the entire file into memory. Whether that is important depends
entirely on the file. But unless the file is extremely large, it
shouldn't be a big problem.

Hugo
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to