[Python-ideas] String formatting and namedtuple

Aahz aahz at pythoncraft.com
Thu Feb 12 23:55:12 CET 2009

On Thu, Feb 12, 2009, George Sakkis wrote:
> On Thu, Feb 12, 2009 at 2:24 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> PROPOSAL: Allow the simple case to stay simple.  Allow field names to be
>> omitted for all fields in a string and then default to 0, 1, ... so that
>> example above could be written as
>> >>> msg = "{} == {}".format
>> Given that computers are glorified counting machines, it *is* a bit annoying
>> to be required to do the counting manually.  I think this is at least half
>> the objection to switching to .format.
> What happens when both empty and non-empty fields appear ? E.g. would
>     'I love {} with {1} and {} with {1}'.format('bacon', 'eggs', 'sausage')
> return 'I love bacon with eggs and eggs with eggs', or it would be
> smarter and see that 1 is used explicitly and skip over it, giving 'I
> love bacon with eggs and sausage with eggs' ?

I'd favor raising an exception.  Alternatively, we could do the
equivalent of what % formatting does, which would be the first option
(that is, '{#}' is considered equivalent to mapped interpolation in %
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.

More information about the Python-ideas mailing list