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

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

SAP BPC EPM dynamic table member -