Most elegant way to do something N times

Chris Angelico rosuav at gmail.com
Mon Dec 23 19:41:51 EST 2019


On Tue, Dec 24, 2019 at 11:34 AM DL Neil via Python-list
<python-list at python.org> wrote:
>
> On 24/12/19 1:04 PM, Chris Angelico wrote:
> > File parsing. You read a section header and want to ignore that
> > section, so you ignore the next 15 lines.
>
> (just to be cheeky to @Chris)
>
> Perhaps better as a Finite State Machine, with one state being 'seeking
> section header'.
> 1 can we guarantee that the 'magic constant' of 15 will always apply?

That number came from the header itself. Okay, so more commonly this
kind of thing is a *byte* count, but I have known some that count
lines, or entries, or something else that you'd have a function to
grab one of.

> 2 presumably the total routine will involve more than identifying a
> single header and skipping (only) that section.

Of course. But after skipping that section (by ignoring X lines), you
go do something else.

ChrisA


More information about the Python-list mailing list