[Python-ideas] Binary f-strings

Sven R. Kunze srkunze at mail.de
Mon Sep 28 19:00:46 CEST 2015

On 28.09.2015 05:03, Chris Angelico wrote:
>>>> восток = 1961
>>>> apollo = 1969
>>>> print(f"It took {apollo-восток} years to get from orbit to the moon.")
> It took 8 years to get from orbit to the moon.
>>>> print(b"It took {apollo-восток} years to get from orbit to the moon.")
>    File "<stdin>", line 1
> SyntaxError: bytes can only contain ASCII literal characters.
> If that were a binary f-string, those Cyrillic characters should still
> be legal (as they define an identifier, rather than ending up in the
> code). Would it confuse (a) humans, or (b) tools, to have these "texty
> bits" inside a byte string?

I don't think so. "{...}" indicates the injection of whatever "..." 
stands for, thus is not part of the resulting string. So, no issue here 
for me.

(The only thing that would confuse me, is that "восток" is an allowed 
identifier in the first place. But that seems to be a different matter.)

> In any case, bf strings can be added later, but once they're added,
> their semantics would be locked in. I'd be inclined to leave them out
> for 3.6 and see what people say. A bit of real-world usage of
> f-strings might show a clear front-runner in terms of expectations
> (UTF-8, ASCII, or something else).

I tend to agree here.


More information about the Python-ideas mailing list