[Tutor] String or Re
Alan Gauld
alan.gauld at btinternet.com
Fri Jul 13 20:40:50 CEST 2007
"Que Prime" <queprime at gmail.com> wrote
> I'm working on the following code to read a log file and output
> lines
> containing '10.52.10.10' but am unsure of whether to use a regular
> expression or string to achive this.
I tend to only use regex for patterns. If its a fixed string the
standard methods are usually easier and faster.
> infile = open("in.txt","r")
> outfile = open("out.txt", "w")
>
> for line in infile:
> if line #contains '10.52.10.10':
try using
if '10.52.10.10' in line:
> outfile.write(line)
>
>
> ofile.close()
> wfile.close()
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list