on str.format and f-strings

Meredith Montgomery mmontgomery at levado.to
Mon Sep 5 19:02:42 EDT 2022


Julio Di Egidio <julio at diegidio.name> writes:

> On Monday, 5 September 2022 at 22:18:58 UTC+2, Meredith Montgomery wrote:
>> r... at zedat.fu-berlin.de (Stefan Ram) writes: 
>
>> > , but with the spaces removed, it's even one character 
>> > shorter than the format expression: 
>> > 
>> > eval('f"The name is {name} and the email is {email}"',d)
>> > "The name is {name} and the email is {email}".format(**d) 
>> 
>> Lol. That's brilliant! Thanks very much!
>
> Calling eval for that is like shooting a fly with a cannon.

Indeed!  But we're not looking for production-quality code.  Just an
extreme way to satisfy a silly requirement.

> Besides, this one is even shorter:
>
> f"The name is {d['name']} and the email is {d['email']}"

This doesn't quite satisfy the requeriments.  We're trying to specify
only the keys, not the dictionary.  (But maybe the requirements did not
say that explicitly.  I'd have to look it up again --- it's been
snipped.  It's not important.  Thanks much for your thoughts!)


More information about the Python-list mailing list