I am a beginner to python and i’m stuck in the assignment given to me.I have a file called file.h which has a certain information and a number in between something like this.
Working copy:C:/tmp
Repository root:svn:/localhost
VERSION_REV 8797
Schedule:normal
Date:13/12/2010
I need to write a python code so that whenever i run it should search for the number 8797 and replace it with a number stored in my variable i.e,x=8798.I tried like below,but not succeeded.
fout = open("path to\file\file.h","r+")
for line in open("path to\file\file.h"):
line = line.replace("VERSION_REV %i","x")
fout.write(line)
fout.close()
Sorry,I forgot to mention the i am using windows7 system.
You can use
re.sub