[Python-ideas] String interpolation for all literal strings
Wes Turner
wes.turner at gmail.com
Fri Aug 7 00:27:37 CEST 2015
On Thu, Aug 6, 2015 at 4:03 PM, Tim Delaney <timothy.c.delaney at gmail.com>
wrote:
> On 6 August 2015 at 16:05, Nathaniel Smith <njs at pobox.com> wrote:
>
>> On Wed, Aug 5, 2015 at 9:35 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> > use "!" as the prefix instead of "f" to more clearly emphasise the
>> > distinction from the subtle effects of "u", "b" and "r"
>>
>> Hey, maybe $ would make an even better string-interpolation sigil anyway?
>>
>
> +1 for $"..." being an interpolated string. The syntax just makes sense.
> Doesn't prevent us from using $ elsewhere, but it does set a precedent that
> it should be used in interpolation/substitution-style contexts.
>
> +0 for !"..." being an interpolated string. It's not particularly obvious
> to me, but I do like the def foo!(ast) syntax, and symmetry with that
> wouldn't be bad. Although I wouldn't mind def foo$(ast) either - $ stands
> out more, and this could be considered a substitution-style context.
>
> -1000 on unprefixed string literals becoming interpolated. But the prefix
> should be able to be used with raw strings somehow ... r$"..."? $r"..."?
>
\{cmd} -- https://en.wikipedia.org/wiki/LaTeX#Examples
https://docs.python.org/2/library/string.html
# str.__mod__
'%s' % cmd
https://docs.python.org/2/library/string.html#template-strings
# string.Template
'$cmd'
'${cmd}'
https://docs.python.org/2/library/string.html#format-string-syntax
# str.format
{0} -- format([]
{cmd!s} -- .format(**kwargs)
#{cmd} -- ruby literals, coffeescript string interpolation
{{cmd}} -- jinja2, mustache, handlebars, angular templates
# Proposed syntax
\{cmd} -- python glocal string [...], LaTeX
\{cmd\} -- "
>
> Tim Delaney
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150806/7474526d/attachment.html>
More information about the Python-ideas
mailing list