On Tue, 8 Feb 2022 at 01:27, Eric V. Smith <eric@trueblade.com> wrote:
On Feb 7, 2022, at 1:55 AM, Chris Angelico <rosuav@gmail.com> 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