peter at engcorp.com
Thu Aug 1 14:37:45 CEST 2002
Sean 'Shaleh' Perry wrote:
> > 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.)
> my point was not to provide a full solution but to point out another style. I
> find that many people knee jerk to regex whenever they are faced with a string
> or parsing problem. Just pointing out that there is another way is important.
I realize that and agree. In this case, though, it actually looked to
me like the regex was the better way and that maybe the "why use regex?"
was -- this time -- almost a knee jerk in the other direction.
Personally, I would probably have done a .read(), then used .find() to
get the locations of the "!" and "end" and then just taken a slice out
of the string to accomplish the same thing... but I think maybe the
regex would _still_ have been easier this time.
More information about the Python-list