On Fri, Feb 27, 2009 at 5:09 AM, prasad rao <prasadarao...@gmail.com> wrote: > Hello > Finally I managed to writ a function to format a file. > Thank to everybody for their tips. > > def mmm(a): > ???? import os,textwrap > ???? so=open(a) > ???? d=os.path.dirname(a)+os.sep+'temp.txt' > ???? de=open(d,'w') > ???? import textwrap > ???? for line in so: > ???????? if len(line)<70:de.write(line+'\n')
You are introducing an extra newline here, line already ends in a newline. > ???????? if len(line)>70: > ???????????? da=textwrap.fill(line,width=60) > ???????????? de.write(da+'\n') Not sure if textwrap strips the trailing newline, if not, this is also double-spacing. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor