re

Max M maxm at mxm.dk
Wed May 29 06:29:27 EDT 2002


Eric Texier wrote:

> I am trying to do replace '#' with a number in string with some control
> over the padding:
> 
> a = 'echo file#.sgi file#~3.sgi file#~5*2.sgi'


If possible you are better of using Pythons string formatting notation 
for this:


val = 3
a = 'echo file%s.sgi file%.3i.sgi file%.5i.sgi' % (val, val, val*2)
print a


 >>>echo file3.sgi file003.sgi file00006.sgi

More in the documentation at:

2.2.6.2 String Formatting Operations

regards Max M




More information about the Python-list mailing list