Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attribute': 0.07; 'advance.': 0.09; 'header:In-reply-to:1': 0.09; 'loop.': 0.09; 'error:': 0.10; 'subject:file': 0.13; '"a")': 0.16; 'innermost': 0.16; 'subject:loops': 0.16; 'subject:writing': 0.16; '\xa0while': 0.16; 'help.': 0.19; "doesn't": 0.22; 'fine,': 0.23; 'code': 0.26; "i'm": 0.28; 'received:144': 0.30; 'thanks': 0.32; 'error.': 0.32; 'loop': 0.34; 'wondering': 0.34; 'hi,': 0.34; 'someone': 0.34; 'to:addr:python-list': 0.35; 'but': 0.37; 'could': 0.38; 'some': 0.38; 'getting': 0.38; 'skip:\xa0 10': 0.39; 'subject:from': 0.39; 'might': 0.40; 'to:addr:python.org': 0.40 MIME-version: 1.0 Content-disposition: inline Content-type: text/plain; charset=iso-8859-1 Date: Wed, 15 Feb 2012 14:12:41 -0600 From: Rituparna Sengupta Subject: writing to a file from within nested loops In-reply-to: <7750b096170a1e.4f3c11b5@wiscmail.wisc.edu> To: python X-Mailer: Oracle Communications Messenger Express 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011) Content-language: en Content-transfer-encoding: quoted-printable X-Accept-Language: en Priority: normal X-Spam-Report: AuthenticatedSender=yes, SenderIP=144.92.8.24 X-Spam-PmxInfo: Server=avs-14, Version=5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.2.15.200046, SenderIP=144.92.8.24 References: <75208cce174437.4f3bf1a2@wiscmail.wisc.edu> <77a0ddfa17203f.4f3bf1de@wiscmail.wisc.edu> <775093eb1740b6.4f3bf21b@wiscmail.wisc.edu> <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> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1329336768 news.xs4all.nl 6870 [2001:888:2000:d::a6]:51252 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20468 Hi=2C I=27m working on this code and I keep getting an error=2E It might be so= me very basic thing but I was wondering if someone could help=2E Its a l= oop within a loop=2E The part outside the innermost loop gets printed fi= ne=2C but the part within the innermost loop doesn=27t get printed=2E I = get an error=3A =27str=27 has no attribute =27write=27=2E Thanks in adva= nce=2E Ritu =2E =2E =2E i=3D0 =A0while i=3Cm =A0r=3Dname=5Bi=5D =A0f=3Dopen(=27file=27+=27=25s=27 =25(r)=2C =22a=22) =A0f=2Ewrite(=22whatever=22+r) =A0 =A0=23part outside innermost loop get= s printed =A0j=3D0 =A0 while j=3Cn =A0 f=2Ewrite(=22output of loop=22) =A0=23part within innermost loop doe= sn=27t get printed =A0 j=3Dj+1 =A0f=2Eclose() =A0i=3Di+1