python - how to split up a large text file (one long string) into 50kb text files -


i have file "text.txt" 1.1mb right now. want split 50kb text files. use loop if readlines() file, since it's 1 long string, i'm not sure that.

open file, set byte range iterate through, seek() location, read() in content, and, if there content, write new file. if there's no content, break out of loop.

with open('myfile.txt', 'r') f:     place in range(0, int(2e6), 50000):         f.seek(place)         content = f.read(50000)         if content:             open('myfile{}.txt'.format(place), 'w') o:                 o.write(content)         else:             break 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -