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.ga...@btinternet.com>wrote: > > *From:* Spencer Parker <inthefri...@gmail.com> > ***Cc:* tutor@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/ > > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor