[Tutor] simple search and replace...

Spencer Parker inthefridge at gmail.com
Wed Mar 31 22:34:19 CEST 2010


I was on the right track...looking more for advice than anything.  Regex
could get too complicated for what I am doing.  I also maintain the list in
a different config file because it does change from time to time...we add
and delete depending on what we are doing.  Something like this adds a lot
more flexibility.

Thanks again!

On Wed, Mar 31, 2010 at 1:51 PM, ALAN GAULD <alan.gauld at btinternet.com>wrote:

>
> *From:* Spencer Parker <inthefridge at gmail.com>
> ***Cc:* tutor at python.org
> *Sent:* Wednesday, 31 March, 2010 20:30:56
> *Subject:* Re: [Tutor] simple search and replace...
>
> That was only a small example of a message...the message contains several
> elements.  If I have the PID segment then I have OBR segment...an OBX, etc.
>  So it would have to cycle through finding each element that is in the
> message till the end.  I actually meant a list and not a
> dictionary...terminology confusion in my head.
>
> OK I suspected as much.
>
> But if it's fixed patterns you can either do a replace()
> in a loop over your patterns:
>
> for pat in ['PID','OBR',....]
>     h7string = h7string.replace('\n'+pat, h7string)
>
> Or even build a regex that does it all in one.
> (But the regex could get complex quickly!)
>
>  Alan Gauld
> Author of the Learn To Program website
>
> http://www.alan-g.me.uk/
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100331/d74418f2/attachment-0001.html>


More information about the Tutor mailing list