[Python-Dev] summary of transitioning from % to {} formatting
Nick Coghlan
ncoghlan at gmail.com
Mon Oct 5 22:41:25 CEST 2009
Barry Warsaw wrote:
> On Oct 4, 2009, at 4:11 AM, Nick Coghlan wrote:
>
>> Barry Warsaw wrote:
>>> I also don't think this is a case of anti-TOOWTDI. For most situations
>>> {}-strings are great (IMO), but in the specific translation domain, I
>>> suspect $-strings are still better.
>>
>> I agree that keeping string.Template around is valid due to its focus on
>> being very simple to use (especially for non-coders producing
>> translation templates)
>>
>> However, string.Template is already set up to work for the relevant APIs
>> in that domain so I don't think it will really be affected by any
>> changes to the underlying language and library support for brace
>> formatting.
>
> What if you wanted to translate log messages? Printing to a StringIO
> first really isn't a very good solution.
Oh, I see what you meant now - you were pointing out that lazy
formatting APIs (such as logging) already don't work properly for
alternative formatting mechanisms (such as string.Template).
(Although printing to a String IO doesn't seem necessary - simply
pre-formatting the message seems like it should work, just as
preformatting brace formatted messages already works today).
The idea of adding an optional "fmt_style" callable to these APIs
(defaulting to None, which would imply the use of the mod operator) is
becoming more appealing...
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev
mailing list