[issue24549] string.format() should have a safe_substitute equivalent, to be run consecutively

Steven D'Aprano report at bugs.python.org
Thu Jul 2 04:31:02 CEST 2015


Steven D'Aprano added the comment:

I don't think that this behaviour is desirable, certainly not by default. If I write "{1} {0}".format('one') that's clearly a programming error and I should get an exception. Chaining a second .format method call afterwards does not make the first one any less of a mistake.

I think that there may be a good argument to be made for a safe_format with *named* arguments, like string.Template, but not positional arguments. But that would require some discussion, to decide on the correct behaviour. And why not use string.Template in the first place, or make the chained calls a single call?

"{1} {0}".format('one', 'two')

is clearly the most obvious way to do it. A slightly less obvious way:

"{{}} {}".format('one').format('two')

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24549>
_______________________________________


More information about the Python-bugs-list mailing list