[Python-ideas] Draft PEP on string interpolation

Nathaniel Smith njs at pobox.com
Mon Aug 24 02:39:50 CEST 2015


On Sun, Aug 23, 2015 at 5:35 PM, Eric V. Smith <eric at trueblade.com> wrote:
> On a more serious note, I'm thinking of adding i-strings to my f-string
> implementation. I have some ideas that the format_spec (the :.3f stuff)
> could be used by the code that eventually does the string interpolation.
> For example, sql(i-string) might want to interpret this expression using
> __sql__, instead of how str(i-string) would use __format__. Then the
> sql() machinery could look at the format_spec and pass it to the value's
> __sql__ method.
>
> For example:
> sql(i'select {date:as_date} from {tablename}'
>
> might call date.__sql__('as_date'), which would know how to cast to the
> write datatype (this happens to me all the time).

Another use case would be when using an HTML-sensitive interpolater,
one would want a way to mark that one particular substitution-string
is already HTML-encoded and does not need further quoting.

-n

-- 
Nathaniel J. Smith -- http://vorpus.org


More information about the Python-ideas mailing list