Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20468
| Date | 2012-02-15 14:12 -0600 |
|---|---|
| From | Rituparna Sengupta <rsengupta@wisc.edu> |
| Subject | writing to a file from within nested loops |
| References | (3 earlier) <7760fe7a17153d.4f3bf258@wiscmail.wisc.edu> <75909037172f2d.4f3bf294@wiscmail.wisc.edu> <76f0965b175c1f.4f3bf2d0@wiscmail.wisc.edu> <77c0ac1d173db4.4f3bf403@wiscmail.wisc.edu> <7750b096170a1e.4f3c11b5@wiscmail.wisc.edu> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5849.1329336768.27778.python-list@python.org> (permalink) |
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[i]
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
writing to a file from within nested loops Rituparna Sengupta <rsengupta@wisc.edu> - 2012-02-15 14:12 -0600
csiph-web