String formatting with %s

Mel mwilson at the-wire.com
Sun Dec 2 11:38:55 EST 2007


Donn Ingle wrote:
  > Now, is there something quick like:
>>>> s = "%s/2 and %s/1" % ( "A", "B" )
>>>> print s
> B and A
> 
> ?

GNU glibc printf accepts a format string:

printf ("%2$s and %1$s", "A", "B");

to produce what you want -- but not Python, AFAIK.


	Mel.



More information about the Python-list mailing list