Let's say I have a list with 10,000 entries. The user inputs a number, say 10. What I need to do is write all of the entries in the list to .txt files, but only 10 to each file. So the program would write the first 10, and then create a new file, and write the next 10... etc.
Thanks
count = 0
ext = 0
path = 'New/' + str(ext) + '.txt'
open(path, 'a').close()
for line in flines:
f = open(path, 'a')
if count <= x:
f.write(line)
count += 1
else:
ext += 1
path = 'New/' + str(ext) + '.txt'
count += x
f.close()
This is what I've tried, amongst some other solutions. I have a feeling that I'm missing something simple.
This is different to the other question pointed out above as that's talking about a text file and this is talking about a list.