[Tutor] simple search and replace...
alan.gauld at btinternet.com
Wed Mar 31 21:51:00 CEST 2010
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!)
Author of the Learn To Program website
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor