The expansion of f-strings is a welcome addition. The more I use them, the happier I am that they exist
https://docs.python.org/3/whatsnew/3.8.html#f-strings-suppor...
https://docs.python.org/3/whatsnew/3.8.html#f-strings-suppor...
{ k: eval(k) for k in ('theta', 'delta.days', 'cos(radians(theta))') }
This would trivially subsume the f'{user=}' syntax for the example given: just print out the dictionary. But it'd also be useful for: filling template dictionaries; printing out status pages for HTTP webservers; returning multiple variables from a function; flattening out complex data structures; creating dispatch tables out of local functions.You could even have a syntax like locals('theta', 'delta.days') and keep it familiar.
There's an Elixir library with macros to make a map (dictionary) using the variable names passed in [1]:
iex> import ShorterMaps
...> name = "Chris"
...> id = 6
...> ~M{name, id}
%{name: "Chris", id: 6}
Though wether its a good idea or not is another question. ;) If you want to do the type of programming you're talking about you should try Elixir/Julia/Clojure(/Rust?)... or any number of other languages with macros.Will it print what foo is if I type logger.info("{foo=}")?
The way I see it, it's a necessary price to pay, and I just continue to use c-style forming strings in logging.
As far I understand the following:
print(f"your name is {name}")
is roughly equivalent to: print(f"your name is " + format(name))
What is there to parse?From: ckpt-8-0.300 To: epoch=8, val_loss=0.300