[Python-ideas] Draft PEP on string interpolation
Chris Rebert
pyideas at rebertia.com
Fri Aug 21 19:48:01 CEST 2015
On Thu, Aug 20, 2015 at 11:40 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 21 August 2015 at 12:52, Guido van Rossum <guido at python.org> wrote:
<snip>
> It's the opposite of the "interpolating untrusted strings that may
> contain aribtrary expressions" problem - what happens when the
> variables being *substituted* are untrusted? It's easy to say "don't
> do that", but if doing the right thing incurs all the repetition
> currently involved in calling str.format, we're going to see a *lot*
> of people doing the wrong thing. At that point, the JavaScript
> backticks-with-arbitrary-named-callable solution starts looking very
> attractive:
>
> myquery = sql`SELECT $column FROM $table;`
> mycommand = sh`cat $filename`
> mypage = html`<html><body>$content</body></html>`
>
> At that point, internationalisation could just be:
>
> translated = _`This $value and this $other_value are interpolated
> after translation lookup`
The problem with such syntax is that Guido already long ago ruled out
using backticks for anything in Python 3:
"""
No more backticks.
Backticks (`) will no longer be used as shorthand for repr -- but that
doesn't mean they are available for other uses. Even ignoring the
backwards compatibility confusion, the character itself causes too
many problems (in some fonts, on some keyboards, when typesetting a
book, etc).
""" -- https://www.python.org/dev/peps/pep-3099/
Regards,
Chris
--
http://chrisrebert.com
More information about the Python-ideas
mailing list