One way is...<br><br>CODE<br>############<br>#!/usr/bin/python<br><br>handle = file(&quot;test.txt&quot;,&#39;a&#39;)<br>number = 1<br>for num in range(1,5):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handle.write(&quot;TestingSome%s\n&quot; % (number))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handle.write(&quot;something%s-test\n&quot; % (number))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number += 1<br>handle.close()<br><br>OUTPUT<br>############<br>TestingSome1<br>something1-test<br>TestingSome2<br>something2-test<br>TestingSome3<br>
something3-test<br>TestingSome4<br>something4-test<br><br><br><br><div><span class="gmail_quote">On 5/21/07, <b class="gmail_sendername">Andreas Kostyrka</b> &lt;<a href="mailto:andreas@kostyrka.org">andreas@kostyrka.org</a>
&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA1<br><br>Well, there are a number of ways to achieve this, but the classical one
<br>would be:<br><br>&quot;&quot;&quot;abc%(i)s<br>def%(i)s<br>&quot;&quot;&quot; % dict(i=1)<br><br>Andreas<br><br>Chandrashekar wrote:<br>&gt; Hi,<br>&gt;<br>&gt; I am trying to do something like this in python. Can you please help?
<br>&gt;<br>&gt; handle= open(&#39;test.txt&#39;,&#39;a&#39;)<br>&gt;<br>&gt; handle.write(&#39;&#39;&#39;<br>&gt;<br>&gt; Testsomething$i<br>&gt;<br>&gt; something$i-test<br>&gt;<br>&gt; &#39;&#39;&#39;<br>&gt; )<br>&gt;
<br>&gt; when i write into the file, i would like to have the output like this.<br>&gt;<br>&gt; Testsomething1<br>&gt; something1-test<br>&gt; Testsomething2<br>&gt; something2-test<br>&gt; Testsomething3<br>&gt; something3-test
<br>&gt; .......<br>&gt;<br>&gt; I can perform the same using a loop. But how do i append i (1,2,......n)<br>&gt; while i am writing into the file.(I mean inside the handle.write)<br>&gt;<br>&gt; Thanks,<br>&gt; Chandru<br>
&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt; Pinpoint customers<br>&gt; &lt;<a href="http://us.rd.yahoo.com/evt=48250/*http://searchmarketing.yahoo.com/arp/sponsoredsearch_v9.php?o=US2226&amp;cmp=Yahoo&amp;ctv=AprNI&amp;s=Y&amp;s2=EM&amp;b=50">
http://us.rd.yahoo.com/evt=48250/*http://searchmarketing.yahoo.com/arp/sponsoredsearch_v9.php?o=US2226&amp;cmp=Yahoo&amp;ctv=AprNI&amp;s=Y&amp;s2=EM&amp;b=50</a>&gt;who<br>&gt; are looking for what you sell.<br>&gt;<br>&gt;
<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>&gt; Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org
</a><br>&gt; <a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG v1.4.2 (GNU/Linux)<br>Comment: Using GnuPG with Mozilla - 
<a href="http://enigmail.mozdev.org">http://enigmail.mozdev.org</a><br><br>iD8DBQFGUVPtHJdudm4KnO0RAgZwAJ9XOamfWZHd1CXYGuLIlOP11p7PWwCgxPD7<br>UILsdZNbknZz4zq71EuvxSs=<br>=0y02<br>-----END PGP SIGNATURE-----<br>_______________________________________________
<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>