The following code is supposed to replace a line in a file called "some_file" then use the new version of "some_file" in a python command and then repeat the process. When I run it the line in the file gets iteratively replaced based on the value of i with the new values but the further command doesn't use the new version of the file but the old one. Could someone give me a way around this problem?
for i in range(0,N):
with fileinput.input("some_file", inplace=True) as file:
for line in file:
print(line.replace("something", "something_else", 1), end='')
python command using "some_file"