[Python-ideas] Draft PEP on string interpolation

Mike Miller python-ideas at mgmiller.net
Sat Aug 22 07:52:23 CEST 2015


Hi,

I'm not sure that's the case any more, after reading the threads here this week 
there are numerous difficulties with trying to reconcile both use cases, and 
didn't get the feeling anyone has an elegant solution to them.

We could implement f'' and (i'', aka t'') using either syntax of course, parsing 
variables from the string, but choosing translation with str.format() seems to 
cause several more issues than (string.Template() and a bit of inconsistency does).

Which syntax would you rather have for translation?  (Knowing that you might 
give a different answer for standard interpolation.)

-Mike


On 08/21/2015 06:38 PM, Barry Warsaw wrote:
> On Aug 21, 2015, at 04:21 PM, Mike Miller wrote:
>
>> The more I think about it, trying to push str.format() (or similar) syntax
>> into i18n is just too much.  We'll need a different prefix anyway because of
>> the compile/runtime differences so why not stick with str.Template
>> formatting?
>>
>> It fits the use case perfectly, and requires little additional work.
>
> The main annoyance with string.Template based approaches is the same as
> str.format() -- the requirement to use sys._getframe() to access the
> interpolation values.  I think this was one of the main reasons to propose new
> syntax, since the compiler can parse the interpolation string and arrange for
> the values to be composed into a substitution dictionary without having to do
> ugly locals/globals references.  I think this is also Guido's main gripe about
> the current function-based implementations.
>
> I still wish we could solve this more limited problem, but I don't see a way
> around that without adding syntax, and if you're going to do that, then I
> think most people want to go down the whole PEP 498/501 road.
>
> Cheers,
> -Barry
>


More information about the Python-ideas mailing list