~/talk

How to format strings for logging in Python

Talkat PyData Global 2022 · 2022-12-01..12-03· [python, developer-experience]
links:none on file
slides:none on file

Claim: f-strings are fastest when messages are emitted but percent-style logging defers formatting when a message is suppressed. Timing examples show ~890 µs vs ~990 µs when printed and 280 ns vs 500 ns when suppressed, so absolute differences are tiny. Demonstration uses Python logging module and microbenchmarks. Security example shows crafted format padding can produce one gigabyte of whitespace and freeze a program. Recommendation: prefer f-strings for readability, use deferred formatting or validate untrusted format strings for safety.

AI-written summary · about

~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.