[Python-ideas] Custom string prefixes

Masklinn masklinn at masklinn.net
Mon May 27 14:47:45 CEST 2013


On 2013-05-27, at 14:28 , Yuval Greenfield wrote:
> On Mon, May 27, 2013 at 1:41 PM, Göktuğ Kayaalp <goktug.kayaalp at gmail.com>wrote:
> 
>> I think it would add some significant flexibility to Python to let users
>> define custom string prefixes. What I mean by a string prefix is,
>> a letter prefixing the string literal, modifying the behavior of it,
>> [...]
>> 
> 
> The feature isn't present. But it isn't really clear what you want either.

Regardless of the implementation details (which can be bikeshed
separately afterwards if the idea is considered worthy), there seem to
be 2 different suggestions in my reading:

1. Pluggable string prefixes allowing custom parsing of string literals
   and their resulting in arbitrary types, e.g. a `d` prefix on a string
   literal would yield a decimal.Decimal (one can also imagine an
   `h`-string for markup-safe strings literals[1] for instance)

2. Some sort of codegen/environment hook allowing (amongst other
   things?) the implementation of shell/ruby/perl string interpolation
   (Scala uses prefixes for interpolator specifications[2])

[1] https://pypi.python.org/pypi/MarkupSafe
[2] http://docs.scala-lang.org/overviews/core/string-interpolation.html


More information about the Python-ideas mailing list