On replacing % formatting with str.format

T

Terry Reedy

Guido intends that the new str.format and associated facilities
eventually replace the old % formatting operator. But when? (Why is a
different question discussed elsewhere, but includes elimination of a
couple of problems and greatly increased flexibility and extendibility.)

A few month ago, Guido asked about barriers to switching and two primary
issues came up:

1. No automatic conversion. A couple of people said that would work on
this but I do not know the status.

2. Simple replacement made harder. For example, "Put the $s in the $s
until $s." had to be rewritten as "Put the {0} in the {1} until {2},".
This is harder to write because each replacement field requires not just
an extra character, but also two shift-unshift sequences instead of one.
Plus, one could make a mistake in numbering, or add and delete a field
and have to renumber. Ugh.

So I suggested that we let the interpreter autonumber positional fields,
so we could just write "Put the {} in the {} until {}.", which is about
as easy to type as the $s version. Eric Smith wrote and committed a
patch for 3.1 so we will be able to do that.

So I believe that people just starting with Python, with 2.6, 3.0 (which
should definitely be upgraded to 3.1 when possible), or some with 3.1
should start with the new .format.

Terry Jan Reedy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top