Take the 2-minute tour ×  Instead on reading each and every line
cant we just search for the string in the file and replace it...
i am trying but unable to get any idea how to do thth?  file =
open(C:\\path.txt,"r+") lines = file.readlines()
newString="set:: windows32\n" for l in lines:       if
(re.search("(address_num)",l,re.I) replaceDone==0:
except IOError: share|improve this question i don;t need to use
the for l in lines statement! as it reads the file line by
line... if it is a huge file and the its goign to take lot of
memory –  user2052617 Feb 26 '13 at 3:55 Well, something's going
to have to read through the file somehow to find it - isn't it?
:) –  Jon Clements Feb 26 '13 at 3:56 That’s not valid Python,
and I don’t think that replace is necessary/doing what you think
it does. Could you maybe explain what it is that needs doing in
more detail, please? –  minitech Feb 26 '13 at 3:58
@user2052617: You read the file line-by-line to reduce the
memory usage. –  Blender Feb 26 '13 at 4:00 What is