[Tutor] re Format a file

Lie Ryan lie.1296 at gmail.com
Fri Feb 27 08:29:16 CET 2009


On Fri, 27 Feb 2009 09:59:40 +0530, prasad rao wrote:

> def myform(s):
>      import os
>      so=open(s)
>      d=os.path.dirname(s)+os.sep+'temp.txt'
>      de=open(d,'w')
>      for line in so:
>          while len(line)>60:
>              item=line[60:]
>              try:
>                  a,b=tem.split(' ',1)

what is tem here? It must be a global, since I can't see any other 
reference to tem in the function definition. If tem is global, then the 
value of b (a.k.a. line) will never change (except for the first 
iteration)

>                  de.write(line[:60]+a+'\n')
>                  line=b
>              except ValueError:
>                  pass
>              de.write(line+'\n')
>      so.close()
>      de.close()
>      os.remove(s)
>      os.rename(d,s)



More information about the Tutor mailing list