0
import json

# define list with values
basicList = [1, 2, 3, ..., 10000000]

# open output file for writing
with open('listfile.txt', 'w') as filehandle:  
    json.dump(basicList, filehandle)

I created a very long list and wrote it to a file. How can I now add a single element to the file without reading and rewriting the whole file?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Senju
  • 435
  • 2
  • 5
  • 20

0 Answers0