On Tue, 8 Feb 2022 at 01:27, Eric V. Smith <[email protected]> wrote:
>
>
> > On Feb 7, 2022, at 1:55 AM, Chris Angelico <[email protected]> wrote:
> >
> …
> > def spam():
> > bird = "Norwegian Blue"
> > volts = 4e6
> > return "{volts}V insufficient to voom {bird}".format(**locals())
>
> This is completely off topic, but: the better way to do this is with
> .format_map(locals()).
>
> This public service announcement is part of my goal to increase knowledge of
> format_map().
>
Fair point. Still, my original statement was that it is even better to do it as:
return f"{volts}V insufficient to voom {bird}"
which treats it fully as code. But if the information wasn't from
locals and was from some other dict, then yes, I fully accept the
correction, format_map would have been the correct choice.
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/FGIZLGYEVG6BBOEPJB2H72I2NBMQB6X7/
Code of Conduct: http://python.org/psf/codeofconduct/