-1

I have a large text file and I know the positions of the parts of the code that I would like to change. I am trying to do something similar to this:

infile = open('file.txt', 'rb')
infile.seek(start_position)
text_lenght = end_position - start_position
print(infile.read(text_lenght).upper(), file = infile)

The file is supposed to be modified in place and overwrite the previous text file. Is there a way to do this?

Hope I explained myself clear enough.

Vibramat
  • 167
  • 4

1 Answers1

1
 infile = open('file.txt', 'r+')
 infile.seek(seek_position)
 infile.write(text_to_write)
Dharman
  • 26,923
  • 21
  • 73
  • 125
Kristie
  • 74
  • 8