[Tutor] re Format a file
prasad rao
prasadaraon50 at gmail.com
Fri Feb 27 11:09:35 CET 2009
HelloFinally 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')
???????? if len(line)>70:
???????????? da=textwrap.fill(line,width=60)
???????????? de.write(da+'\n')
???? so.close()
???? de.close()
Any improvements and suggestions are welcome.
Thanks
Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090227/580f9083/attachment.htm>
More information about the Tutor
mailing list