This python page will give you a good introduction to the open() and write() functions within python:
docs.python.org/2/tutorial/inputoutput.html
Once you read in the file, you’ll find the line you want to replace, do some string formatting, and then write that data back out to the file.