writing to a file from within nested loops

Rituparna Sengupta rsengupta at wisc.edu
Wed Feb 15 15:12:41 EST 2012


I'm working on this code and I keep getting an error. It might be some very basic thing but I was wondering if someone could help. Its a loop within a loop. The part outside the innermost loop gets printed fine, but the part within the innermost loop doesn't get printed. I get an error: 'str' has no attribute 'write'. Thanks in advance.


 while i<m
 f=open('file'+'%s' %(r), "a")
 f.write("whatever"+r)    #part outside innermost loop gets printed
  while j<n
  f.write("output of loop")  #part within innermost loop doesn't get printed

More information about the Python-list mailing list