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:
FormatterA
string.Formatterthat 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
:siint, float
:sibint, float
:iectimedelta
:tdtimedelta
:rdFor 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}Bto 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().Options¶
A wide range of options are available for each of these formats.
si,sib, andiecaccept[[fill]align][sign][width][.precision][(threshold)]as options. (e.g.,{variable:>+30.2(1.2)si}would printvariableas 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.tdaccepts[[fill]align][sign][width], using the standard Python meanings for each; e.g.,{delta:+30td}would printdeltain a 30-character wide box with a plus or minus sign.rdaccepts[[fill]align][width], using the standard Python meanings for each.