[Tutor] File parse

Tiger12506 keridee at jayco.net
Wed Jul 18 03:39:33 CEST 2007


> Here you go.
>
> I've been working on something like this, but it's mixing the 2.  Thanks 
> for
> helping me.

Okay. But you still haven't given me a few lines of your input file. The 
"in.txt" that you are using in your code.

> import re
>
> infile = open("in.txt","r")
> outfile = open("out.txt", "w")
>
> patt = 'src=\*10.52.10.10'
>
> m = re.match(line, patt)
>
>
> for line in infile:
>    if z in line:
>        outfile.write(z)
>
>
> ofile.close()
> wfile.close()

Mmmm. This isn't making sense. This is better syntactically. But I will need 
your data file in order to fix the actual regular expression

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

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

patt = re.compile('src=\*10.52.10.10')   # I am absolutely sure this is not 
the re exp you want

for line in infile:
  m = patt.match(line)
  if m:
    outfile.write(m.group()[0])

ofile.close()
wfile.close()
#######################

Give me data. I'll fix your re. ;-)

JS 



More information about the Tutor mailing list