On Thu, Feb 26, 2009 at 4:09 AM, prasad rao <prasadarao...@gmail.com> wrote: > hello > I find it difficult to use horizontal scroll bar to read text documents. > So I want to split lines in the text file in to two lines. > <code> > def myforrmat(source,desty): > ???? so=open(source) > ???? de=open(desty,'w') > ???? for line in so: > ????????? if len(line)<60:de.write(line) > ????????? if len(line)>60: > ????????????de.write(''.join(list(line)[:60])) > ????????????de.write(''.join(list(line)[60:]))
You don't have to convert to list, strings are sequences and support slicing directly. As Lie notes, you have to write a newline between the lines! de.write(line[:60]) de.write('\n') de.write(line[60:]) Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor