pyppin.text.formatter¶
Tools to format numbers, times, etc., using the fancy functions in pyppin.text.
Classes
A |
- class pyppin.text.formatter.Formatter[source]¶
Bases:
Formatter
A
string.Formatter
that includes several new formatting options.Provides a Python string Formatter which, in addition to all of the standard Python formatting, supports a few new formats:
Type
Format specification
Renders as
int, float
:si
int, float
:sib
int, float
:iec
timedelta
:td
timedelta
:rd
For example, you might format a timedelta as
{delta:rd}
to get a string like “3 days from now”, or a number of bytes as{size:sib}B
to get a string like “1.2GB”.To use this class, simply create one of these objects and use its
format()
method the way you would normally usestr.format()
.A wide range of options are available for each of these formats.
si
,sib
, andiec
accept[[fill]align][sign][width][.precision][(threshold)]
as options. (e.g.,{variable:>+30.2(1.2)si}
would printvariable
as a decimal-scale SI number, right-aligned in a 30-character wide block, showing a plus or minus sign, two points after the decimal, and using a threshold of 1.2.) The fill, align, sign, and width arguments are identical to the standard ones defined in Python’s custom string formatting rules; the precision and threshold are defined by the si_prefix function.td
accepts[[fill]align][sign][width]
, using the standard Python meanings for each; e.g.,{delta:+30td}
would printdelta
in a 30-character wide box with a plus or minus sign.rd
accepts[[fill]align][width]
, using the standard Python meanings for each.