Skip to main content

Module pyfmt

Module pyfmt 

Source
Expand description

Python number and string formatting corners that show up in console output: round(x, n), f"{x:.1f}", width padding by character count, s[:n] slicing, and html.escape.

Functions§

commas
f"{n:,}" — thousands separators, sign kept in front.
fixed
f"{x:.{prec}f}", spelling infinities and NaN the way Python does.
head
s[:n] — the first n characters.
html_escape
html.escape(s) with quote=True.
pad_left
f"{s:>width}" — pad on the left to width characters.
pad_right
f"{s:<width}" — pad on the right to width characters.
round_to
round(x, ndigits): correctly rounded on the binary value, ties to even — the same digits CPython’s float.__round__ produces.