vermouth.truncating_formatter module¶
Provides a string formatter that can not only pad strings to a specified length if they’re too short, but also truncate them if they’re too long.
-
class
vermouth.truncating_formatter.
FormatSpec
(fill, align, sign, alt, zero_padding, width, comma, decimal, precision, type)¶ Bases:
tuple
Create new instance of FormatSpec(fill, align, sign, alt, zero_padding, width, comma, decimal, precision, type)
-
property
align
¶ Alias for field number 1
-
property
alt
¶ Alias for field number 3
-
property
comma
¶ Alias for field number 6
-
property
decimal
¶ Alias for field number 7
-
property
fill
¶ Alias for field number 0
-
property
precision
¶ Alias for field number 8
-
property
sign
¶ Alias for field number 2
-
property
type
¶ Alias for field number 9
-
property
width
¶ Alias for field number 5
-
property
zero_padding
¶ Alias for field number 4
-
property
-
class
vermouth.truncating_formatter.
TruncFormatter
[source]¶ Bases:
string.Formatter
Adds the ‘t’ option to the format specification mini-language at the end of the format string. If provided, the produced formatted string will be truncated to the specified length.
-
format_field
(value, format_spec)[source]¶ Implements the ‘t’ option to truncate strings that are too long to the required width.
- Parameters
value – The object to format.
format_spec (str) – The format_spec describing how value should be formatted
Returns –
str – value formatted as per format_spec
-
format_spec_re
= re.compile('(([\\s\\S])?([<>=\\^]))?([\\+\\- ])?(#)?(0)?(\\d*)?(,)?((\\.)(\\d*))?([sbcdoxXneEfFgGn%])?')¶
-