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
  • 963,270
  • 265
  • 3,804
  • 3,187
Senju
  • 425
  • 2
  • 5
  • 19

0 Answers0