[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: re.search question
From: Peter Hansen <peter () engcorp ! com>
Date: 2002-07-31 23:40:40
[Download RAW message or body]
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
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic