[Tutor] simple search and replace...

Spencer Parker inthefridge at gmail.com
Wed Mar 31 17:20:19 CEST 2010


I am writing a script to help me add line breaks at certain segments of HL7
messages.  Not sure if anyone here is familiar with what an HL7 message is
or not.  We receive them out of our database with all the segments on one
line.  I am trying to write a script to allow me to separate them at a
certain point and add a line break.  A message would look like this:

MSH|~^\&|SCW|SMED|COR||20100305123742||ORU^R01|100305123742891|P|2.2|||||||PID|||001109660||TEST^Man||19920519|M||||||||||00055254593|699-63-1152|||||||||||

What I want to do is where it says, PID, is add a line break right before
that to knock it down to a new line.

I currently have a dictionary that contains all of the segments and am
wondering what the best way to approach this is.  I thought about a regular
expression...but...I don't think that is the best way.

The basic file i/o I know...it is the search and carriage I need help with.
 Any ideas?

I was thinking of using a 'for i in segments' statement to run through the
dictionary of items.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100331/87b8aebb/attachment.html>


More information about the Tutor mailing list