[Python-ideas] Briefer string format

Steven D'Aprano steve at pearwood.info
Sat Aug 1 20:25:45 CEST 2015


On Sat, Aug 01, 2015 at 01:43:49PM -0400, Eric V. Smith wrote:

> I really can't decide if I want to allow adjacent f-string concatenation
> or not. I'm leaning towards not. I don't like mixing compile-time
> concatenation with run-time expression evaluation. But my mind is not
> made up.

There's no harm in allowing implicit concatenation between f-strings. 
Possible confusion only creeps in when you allow implicit concatenation 
between f- and non-f-strings.


> One issue that has cropped up:
> 
> Should we support !s and !r, like str.format does? It's not really
> needed, since with f-strings you can just call str or repr yourself:
[...]
> With str.format, !s and !r are needed because you can't put the call to
> repr in str.format's very limited expression syntax. But since f-strings
> support arbitrary expressions, it's not needed.

Wait, did I miss something? Does this mean that f-strings will 
essentially be syntactic sugar for str(eval(s))?

f"[i**2 for i in sequence]"

f = lambda s: str(eval(s))
f("[i**2 for i in sequence]")



-- 
Steve


More information about the Python-ideas mailing list