2 ms·
Whilst percent strings can't, calls to format can. So: log.debug("Unexpected, got {got}".format(got=got)) Or, to just use the available locals to automat
by shakna 6y ago
Whilst percent strings can't, calls to format can.
So:
log.debug("Unexpected, got {got}".format(got=got))
Or, to just use the available locals to automatically fill that in for you:
log.debug("Unexepected, got {got}".format(**locals()))
Or if you want both globals and locals with a preference for locals:
log.debug("Unexepected, got {got}".format(**{**globals(), **locals()}))
- jon_richards 6y agoYes, I was asked by a Junior if they should always use f strings now. There are still a couple situations where you need format, such as when you’re formatting a variable instead of a literal. Also, shoutout to Template for untrusted strings. It’s surprisingly unknown. Most people suggest replace or a custom format function.