[Python-ideas] Binary f-strings

Nick Coghlan ncoghlan at gmail.com
Thu Oct 8 09:39:19 CEST 2015


On 7 October 2015 at 22:34, Andrew Barnert <abarnert at yahoo.com> wrote:
> On Oct 7, 2015, at 04:35, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> The parallel I'd attempt to draw is that:
>>
>>    f"{header}{content}{footer}" is to "{}{}{}".format(header, content, footer)
>>
>> as:
>>
>>    bf"{header:b}{content:b}{footer:b}" would be to b"%b%b%b" %
>> (header, content, footer)
>>
>> To make the behaviour clearer in the latter case, it may be reasonable
>> to *require* an explicit field format code, since that corresponds
>> more closely to the mandatory field format codes in mod-formatting.
>
> Are you suggestive that if a format specifier is given, it must include the format code (which seems perfectly reasonable to me--guessing that :3 means %3b is likely to be wrong more often than it's right…), or that a format specifier must always be given, with no default to :b (which seems more obtrusive and solves less of a problem).

I was thinking the latter, but your idea of ":b" being implied only if
there's no format specifier at all (and otherwise requiring an
explicit "b" or other format code) might be better.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list