I tried this script to divide a large text file (1 GB) into several small text file, but when I execute it, only an empty TXT file is created named "file1.txt"
chunksize = 1000000
fid = 1
with open('texto.txt', encoding="utf-8") as infile:
print("opened correctly")
f = open('file%d.txt' % fid, 'w')
for i, line in enumerate(infile):
print(i)
f.write(line)
print(i, chunksize)
if not i % chunksize:
f.close()
fid += 1
f = open('file%d.txt' % fid, 'w')
f.close()
When I try with a small text file the code works fine