[Python-ideas] extensible template strings

Ryan Gonzalez rymg19 at gmail.com
Thu Aug 20 04:17:43 CEST 2015



On August 19, 2015 9:11:42 PM CDT, Mike Miller <python-ideas at mgmiller.net> wrote:
>Hmm,
>
>I didn't mean to get caught up in Yury's subthread about allowing a
>space 
>between the prefix and string.  I don't think it should be allowed.
>
>The implementations of Javascript, Scala, and Nim don't as far as I
>know:
>
>   foo"bar"

Except for Nim it's not special syntax. You can already do:

echo "Hello, ", "World!"

I believe putting no spaces just changes the precedence, like MoonScript.

>
>is the form.
>
>-Mike
>
>
>On 08/19/2015 04:43 PM, Guido van Rossum wrote:
>> As others have pointed out the syntax is problematic; it's too easy
>to
>> accidentally write
>>
>>    foo "bar"
>>
>> instead of
>>
>>    foo, "bar"
>>
>> How important is it really to *hide* the fact that this involves a
>function call?
>>
>> Perhaps unrelated, I wonder if in a different world, i18n could have
>used
>> _+"string" instead of _("string")? (This would use operator
>overloading.)
>>
>>
>> On Wed, Aug 19, 2015 at 4:14 PM, Mike Miller
><python-ideas at mgmiller.net
>> <mailto:python-ideas at mgmiller.net>> wrote:
>>
>>     I also like this feature (of extensible string prefixes) and have
>>     encountered it in my research with Scala, Nim, and to some extent
>C#.  It
>>     feels like the right way to go, and could make a lot of code just
>>     "disappear".  It's somewhat analogous to context managers/with
>statement.
>>
>>     So far I'm calling these "string processors" and wonder how much
>resistance
>>     there is to the idea.  In short it means you would be able to
>define your
>>     own processors, as Yury mentioned:
>>
>>          f''   ==> Format String
>>          i''   ==> i18n
>>          sql'' ==> Escaped SQL
>>          re''  ==> builds RegEx object
>>
>>     We could include a number of common needs while users could
>implement those
>>     specific to their applications.
>>
>>     (Should we keep them separate from existing prefixes?  I'm not
>sure about
>>     that part, perhaps we could advise that these new ones to be more
>than one
>>     character and not be composable.)
>>
>>     Is there interest in this feature?
>>
>>     -Mike
>>
>>     _______________________________________________
>>     Python-ideas mailing list
>>     Python-ideas at python.org <mailto:Python-ideas at python.org>
>>     https://mail.python.org/mailman/listinfo/python-ideas
>>     Code of Conduct: http://python.org/psf/codeofconduct/
>>
>>
>>
>>
>> --
>> --Guido van Rossum (python.org/~guido <http://python.org/~guido>)
>_______________________________________________
>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/

-- 
Sent from my Nexus 5 with K-9 Mail. Please excuse my brevity.


More information about the Python-ideas mailing list