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:

FormatAbstract

get_format(format)#

Parse format parameters and return appropriate Format object.

Parameters:

format (str)

Return type:

FormatAbstract

Classes

FormatAbstract(fmt, params)

Represent a format string.

FormatFloat(*args, **kwargs)

Represent a format string for floats (type f, e, E).

FormatInteger(*args, **kwargs)

Represent a format string for integers (type d).

FormatNumberAbstract(*args, **kwargs)

Represent a format string for numbers (type d, f, e, E).

FormatString(*args, **kwargs)

Represent a format string for strings (type s).

Exceptions

exception DangerousFormatError#

Bases: FormatError

Dangerous format-string leading to ambiguities.

exception FormatError#

Bases: Exception

Error related to Format object.

exception FormatParsingError#

Bases: FormatError

Could not parse a format-string.

exception FormatValueParsingError#

Bases: FormatError

Could not parse value.

exception InvalidFormatTypeError#

Bases: FormatError

Unsupported type of format-string.