writing to a file from within nested loops

R

Rituparna Sengupta

Hi,

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.

Ritu



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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top