New submission from Terry J. Reedy <tjre...@udel.edu>: 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. ---------- components: Interpreter Core messages: 81837 nosy: tjreedy severity: normal status: open title: Allow auto-numbered replacement fields in str.format() strings type: feature request versions: Python 3.1 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5237> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com