string formatting documentation

Terry Reedy tjreedy at
Mon Jan 19 23:03:32 CET 2009

Alan G Isaac wrote:
>> On Mon, 19 Jan 2009 14:44:01 +0000, Alan G Isaac wrote:
>>> we are supposed to prefer 

No, no 'supposed to's.  You are not even 'supposed to' like or use 
Python.  (Unless, I supposed, an employer demands it.  But that is 
another story.)  Certainly, one is not 'supposed to' prefer the new to 
the carefully picked best use example of the old.  Guido and some 
developers prefer the totality of uses cases and possibilities of 
.format to the same for % formatting.

> On 1/19/2009 10:01 AM Steven D'Aprano apparently wrote:
>> Well, that second example certainly is a WTF. I think we are supposed 
>> to prefer:
>> '{0}{0}'.format('wtf?')
>> to '%%s%s' % 'wtf?' % 'wtf?'
> But your replacement misses the point of the example,

I read it the same way and has the same thought as Steven.
Perhaps all the obviously angry 'wtf?'s distracted me.

> which is that sequential formatting is often needed.
> That is, you need to generate a format string from
> a format string.  More explicitly:
> '{{0}} {0}'.format('earlyinfo').format('lateinfo')
> '%%s %s' % 'earlyinfo' % 'lateinfo'

This is what you should have written.  Having never seen or done this, I 
  first missed the doubled '%%' and read it as a syntax error.

> I would like assurance that it is not deprecated.
> Can you back that?

If you claim something exists, you have the burden of proof.
I have not seen 3.0 emit a % deprecation warning.  Have you?

Last I read, Guido *plans* to deprecate % formatting 'sometime'.

Terry Jan Reedy

More information about the Python-list mailing list