format#
Generate regex from string format, and parse strings.
Parameters of the format-string are retrieved. See Format Mini Language Specification.
Thoses parameters are then used to generate a regular expression, or to parse a string formed from the format.
Only ‘s’, ‘d’, ‘f’, ‘e’ and ‘E’ formats types are supported.
The width of the format string is not respected when matching with a regular expression.
Module Attributes
- FORMAT_REGEX = '((?P<fill>.)?(?P<align>[<>=^]))?(?P<sign>[-+ ])?(?P<z>z)?(?P<alternate>#)?(?P<zero>0)?(?P<width>\\d+?)?(?P<grouping>[,_])?(?P<precision>\\.\\d+?)?(?P<type>[a-zA-Z])'#
The regular expression used to parse a format string.
Follows the Format Specification Mini-Language.
[[fill]align][sign]["z"]["#"]["0"][width][grouping_option]["." precision][type]
Functions
- Format(format)#
Parse format parameters and return appropriate Format object.
- Parameters:
format (str)
- Return type:
- get_format(format)#
Parse format parameters and return appropriate Format object.
- Parameters:
format (str)
- Return type:
Classes
|
Represent a format string. |
|
Represent a format string for floats (type f, e, E). |
|
Represent a format string for integers (type d). |
|
Represent a format string for numbers (type d, f, e, E). |
|
Represent a format string for strings (type s). |
Exceptions
- exception DangerousFormatError#
Bases:
FormatErrorDangerous format-string leading to ambiguities.
- exception FormatParsingError#
Bases:
FormatErrorCould not parse a format-string.
- exception FormatValueParsingError#
Bases:
FormatErrorCould not parse value.
- exception InvalidFormatTypeError#
Bases:
FormatErrorUnsupported type of format-string.