re
Jeff Shannon
jeff at ccvcorp.com
Wed May 29 19:24:35 EDT 2002
In article <3CF4AD87.9050206 at mxm.dk>, Max M says...
> 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
If you're expecting the inserted text to always be decimal
numbers, then you're better off using the %d formatting code
instead of %s or %I --
a = 'echo file%d.sgi file%03d.sgi file%05d.sgi' % (val,val,val*2)
--
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list