It is not being added. This "conversion" step has always been a part of the format string syntax for .format(). Only the a conversion is being "added", and that's already in 3.5 - which I'd say is just correcting an oversight, given that the builtin ascii does the same sort of thing that str and repr do.
The double brace is also super weird.
It's again the same escaping that .format() uses.
Why would escaping braces not use backslashes, like, y'know, every other thing that needs to be escaped?
Because that isn't even true for the other main method of formatting:
>>> "spam \%s spam %s and spam" % "eggs"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
>>> "spam %%s spam %s and spam" % "eggs"
'spam %s spam eggs and spam'
See? It even uses the same doubling-up approach. It can't just use a single backslash because that's interpreted (to determine the contents of the format string) at compile-time, while the interpolation is done at run-time. But it doesn't work with a double backslash, either:
>>> "spam \\%s spam %s and spam" % "eggs"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
Sure, it works for regexes, but that's more for traditional/historical reasons. (And it's awkward enough that people end up using raw strings for their regexes anyway.)
2
u/zahlman the heretic Sep 09 '15
It is not being added. This "conversion" step has always been a part of the format string syntax for
.format(). Only theaconversion is being "added", and that's already in 3.5 - which I'd say is just correcting an oversight, given that the builtinasciidoes the same sort of thing thatstrandreprdo.It's again the same escaping that
.format()uses.Because that isn't even true for the other main method of formatting:
See? It even uses the same doubling-up approach. It can't just use a single backslash because that's interpreted (to determine the contents of the format string) at compile-time, while the interpolation is done at run-time. But it doesn't work with a double backslash, either:
Sure, it works for regexes, but that's more for traditional/historical reasons. (And it's awkward enough that people end up using raw strings for their regexes anyway.)