import fileinput
for line in fileinput.input('inFile.txt', inplace=True):
print line.rstrip().replace('oldLine', 'newLine'),
This replaces all lines with the text 'oldLine'
, if you want to replace only the first one then you need to add a condition and break out of the loop.
Adding rstrip() avoids adding an extra space after each line