re.search question
Peter Hansen
peter at engcorp.com
Wed Jul 31 19:40:40 EDT 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.)
-Peter
More information about the Python-list
mailing list