Message81837
3.x str.format() format strings denote replacement fields with braces
{}. Currently, replacement fields *must* contain "either the numeric
index of a positional argument, or the name of a keyword argument". [lib
ref / builtin types / sequence types / string methods /str.format()]
For simple sequential positional replacements, such as:
"{0} is {1} {2}".format('Numbering fields', 'an annoying', 'nuisance')
the writer has to do what computers are so good at, counting, and what
was *not* required with % interpolation, where one could write more simply
"%s is %s %s" % (('Auto-numbering', 'a convenient', 'feature')
.
Proposal: Allow field names to be omitted for all fields in a string and
then default to 0, 1, ... so one could also write
"{} is {} {}".format('Auto-numbering', 'a convenient', 'feature'
This proposal is currently all or nothing for simplicity of description
and presumed ease of implementation. The patch to the doc could then be
"If all replacement fields are left blank, then sequential indexes 0,
1, ... will be automatically inserted."
inserted after the phrase quoted above. Mixing blank and non-blank
specs would then be an error and raise an exception.
This idea was posted today on Python-ideas thread "String formatting and
named tuple". So far, +1 from Aahz, Raymond Hettinger, and Mathias
Panzenbock. |
|
Date |
User |
Action |
Args |
2009-02-12 23:28:49 | terry.reedy | set | recipients:
+ terry.reedy |
2009-02-12 23:28:49 | terry.reedy | set | messageid: <1234481329.65.0.197500970463.issue5237@psf.upfronthosting.co.za> |
2009-02-12 23:28:48 | terry.reedy | link | issue5237 messages |
2009-02-12 23:28:47 | terry.reedy | create | |
|