[Tutor] string replacement

Andreas Kostyrka andreas at kostyrka.org
Mon May 21 10:10:21 CEST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well, there are a number of ways to achieve this, but the classical one
would be:

"""abc%(i)s
def%(i)s
""" % dict(i=1)

Andreas

Chandrashekar wrote:
> Hi,
> 
> I am trying to do something like this in python. Can you please help?
> 
> handle= open('test.txt','a')
> 
> handle.write('''
> 
> Testsomething$i
> 
> something$i-test
> 
> '''
> )
> 
> when i write into the file, i would like to have the output like this.
> 
> Testsomething1
> something1-test
> Testsomething2
> something2-test
> Testsomething3
> something3-test
> .......
> 
> I can perform the same using a loop. But how do i append i (1,2,......n)
> while i am writing into the file.(I mean inside the handle.write)
> 
> Thanks,
> Chandru
> 
> ------------------------------------------------------------------------
> Pinpoint customers
> <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>who
> are looking for what you sell.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGUVPtHJdudm4KnO0RAgZwAJ9XOamfWZHd1CXYGuLIlOP11p7PWwCgxPD7
UILsdZNbknZz4zq71EuvxSs=
=0y02
-----END PGP SIGNATURE-----


More information about the Tutor mailing list