The time has come to convert all prints into logging calls in a library I'm maintaining. Some of the print calls are using str.format, like this (simplified):
>>> n = 4000000
>>> print(f"this bird wouldn't voom if you put {n:,} volts through it!")
this bird wouldn't voom if you put 4,000,000 volts through it!
When I try to log it:
>>> log.warning("this bird wouldn't voom if you put %d, volts through it!", n)
WARNING:root:this bird wouldn't voom if you put 4000000, volts through it!
Seems this is not specifying the thousands separator correctly. How do you specify the thousands separator when using the %-formatting syntax which Python's stdlib logging module necessitates?
Currently using this workaround, which does give the desired output, but seems wrong since the variable is formatted first using str.format and then formatted as a string again, instead of logging as a number directly:
>>> log.warning("this bird wouldn't voom if you put %s volts through it!", format(n, ','))
WARNING:root:this bird wouldn't voom if you put 4,000,000 volts through it!