[Python-Dev] PEP-498: Literal String Formatting
Eric V. Smith
eric at trueblade.com
Tue Aug 11 19:33:40 CEST 2015
On 08/11/2015 01:25 PM, Sven R. Kunze wrote:
> Couldn't you just store the original format string at some
> __format_str__ attribute at the formatted string? Just in case you need it.
>
> x = f'{a}'
>
> =>
>
> x = '{}'.format(a) # or whatever it turns out to be
> x.__format_str__ = '{a}'
Yes. But I think the i18n problem, as evidenced by the differences in
PEPs 498 and 501, relate to the expression evaluation, not to keeping
the original string.
But if people think that this helps the i18n problem, I suggest
proposing concrete changes to PEP 501.
Eric.
>
>
> On 11.08.2015 17:16, Eric V. Smith wrote:
>> On 08/11/2015 11:09 AM, Alexander Walters wrote:
>>> This may seam like a simplistic solution to i18n, but why not just add a
>>> method to string objects (assuming we implement f-strings) that just
>>> returns the original, unprocessed string. If the string was not an
>>> f-string, it just returns self. The gettext module can be modified, I
>>> think trivially, to use the method instead of the string directly.
>> You need the original string, in order to figure out what it translates
>> to. You need the values to replace into that string, evaluated at
>> runtime, in the context of where the string appears. And you need to
>> know where in the original (or translated) string to put them.
>>
>> The problem is that there's no way to evaluate the values and, before
>> they're substituted in to the string, use a different template string
>> with obvious substitution points. This is what PEP 501 is trying to do.
>>
>> Eric.
>>
>>
>> _______________________________________________
>> Python-Dev mailing list
>> Python-Dev at python.org
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe:
>> https://mail.python.org/mailman/options/python-dev/srkunze%40mail.de
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/eric%2Ba-python-dev%40trueblade.com
>
>
More information about the Python-Dev
mailing list