One way is...<br><br>CODE<br>############<br>#!/usr/bin/python<br><br>handle = file("test.txt",'a')<br>number = 1<br>for num in range(1,5):<br> handle.write("TestingSome%s\n" % (number))<br>
handle.write("something%s-test\n" % (number))<br> 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> <<a href="mailto:andreas@kostyrka.org">andreas@kostyrka.org</a>
> 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>"""abc%(i)s<br>def%(i)s<br>""" % dict(i=1)<br><br>Andreas<br><br>Chandrashekar wrote:<br>> Hi,<br>><br>> I am trying to do something like this in python. Can you please help?
<br>><br>> handle= open('test.txt','a')<br>><br>> handle.write('''<br>><br>> Testsomething$i<br>><br>> something$i-test<br>><br>> '''<br>> )<br>>
<br>> when i write into the file, i would like to have the output like this.<br>><br>> Testsomething1<br>> something1-test<br>> Testsomething2<br>> something2-test<br>> Testsomething3<br>> something3-test
<br>> .......<br>><br>> I can perform the same using a loop. But how do i append i (1,2,......n)<br>> while i am writing into the file.(I mean inside the handle.write)<br>><br>> Thanks,<br>> Chandru<br>
><br>> ------------------------------------------------------------------------<br>> Pinpoint customers<br>> <<a href="http://us.rd.yahoo.com/evt=48250/*http://searchmarketing.yahoo.com/arp/sponsoredsearch_v9.php?o=US2226&cmp=Yahoo&ctv=AprNI&s=Y&s2=EM&b=50">
http://us.rd.yahoo.com/evt=48250/*http://searchmarketing.yahoo.com/arp/sponsoredsearch_v9.php?o=US2226&cmp=Yahoo&ctv=AprNI&s=Y&s2=EM&b=50</a>>who<br>> are looking for what you sell.<br>><br>>
<br>> ------------------------------------------------------------------------<br>><br>> _______________________________________________<br>> Tutor maillist - <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>-----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 - <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>