I would like to find and replace a string in a file. I know how to do this, but I can only do it for all instances. Is there a way to do it for just the first instance of the string in the file?
import fileinput
for line in fileinput.FileInput("text.txt", inplace=1):
line=line.replace("hello","hello2")
print line