[Tutor] File parse

Tiger12506 keridee at jayco.net
Wed Jul 18 07:30:36 CEST 2007


>I sent a sample of the file "testin.txt" in the last email.  Here are the
> lines themsevles:

Oh! Sorry. I didn't look in the attachments - I expected the lines in the 
email. My mistake.
Try this ~~   :-P


##############################
import re

infile = open("testin.txt","r")
outfile = open("out.txt","w")

patt = re.compile(r".*src=([\d\.]*) dst=([\d\.]*).*")

for line in infile:
  m = patt.match(line)
  if m:
    outfile.write("src=%s dst=%s\n"%m.groups())

infile.close()
outfile.close()
#############################

Seeing the input file makes me wonder if regular expressions is over kill in 
this instance.

JS 



More information about the Tutor mailing list