[Python-ideas] Custom string prefixes

Yuval Greenfield ubershmekel at gmail.com
Mon May 27 15:13:13 CEST 2013


On Mon, May 27, 2013 at 3:47 PM, Masklinn <masklinn at masklinn.net> wrote:

> 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)
>
>

For this specific use-case I'd suggest

    d = decimal.Decimal
    d('1.0')



> 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])
>
>
A friend of mine likes to do this:

    import sys
    '{sys}'.format(**locals())


Yuval Greenfield
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130527/730baf57/attachment.html>


More information about the Python-ideas mailing list