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

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

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

javascript - Restarting Supervisor and effect on FlaskSocketIO -