I need to read a .txt file with python 3.3 line by line and split the length of characters (format: MEHSAOSHAHSHSUDO....) into 513 character chunks. My code works for the first line however the nextline does not work and I cannot work out why.
I am also confused on how to get the code to repeat the nextline function until the end of the file. The file is around 500 lines long.
This is what I have so far:
with open('bsxlength.txt' , 'r') as string:
first_line = string.readline()
n = 513
print [first_line[i:i+n] for i in range(0, len(first_line), n)]
next_line = string.readline(+2)
n = 513
print [next_line[i:i+n] for i in range(0, len(next_line), n)]
Thankyou
The ultimate goal is to make it split the lines into 513 chunks and if there is not enough for a chunk e.g. the line is 600 letters long to count back the appropriote amount of letters (e.g. 87) and make a new chunk. But one step at a time eh