Peter Hansen peter at
Thu Aug 1 01:40:40 CEST 2002

Sean 'Shaleh' Perry wrote:
> Why use a regex here?
> NOT_READY, READY = (0, 1)
> print '!'
> for line in input:
>     if line == '!':
>         state = READY
>     elif line == 'end':
>         state = NOT_READY:
>     elif state == READY:
>         print line
> print 'end'

Maybe because it's simpler to write (if you know how) and therefore
less bug prone?  <1/2 wink>

(Add "state = None" somewhere at the start of the above and you might
be able to run it.  Then you'll have to create a list, too, and append
each line to it as you go, then return it all with a ''.join(thelist)
before you accomplish the same as the regex Hans posted.)


More information about the Python-list mailing list