pyppin.text.sign

[View Source]

Common classes for printf-like sign-printing conventions.

Functions

format_sign(formatted_unsigned, sign_mode, ...)

Apply a Sign to a formatted number.

Classes

Sign(value)

Equivalent to printf's "-" option, controlling when plus and minus signs should be shown.

class pyppin.text.sign.Sign(value)[source]

Bases: Enum

Equivalent to printf’s “-” option, controlling when plus and minus signs should be shown.

NEGATIVE_ONLY = 0[source]

show signs only for negative numbers.

Type

The default, equivalent to printf -

POSITIVE_AND_NEGATIVE = 1[source]

Show signs for both positive and negative numbers.

Type

Equivalent to printf +

SPACE_FOR_POSITIVE = 2[source]

Show minus sign for negative and space for positive.

Type

Equivalent to printf space

classmethod parse(format_spec: str) Tuple[Sign, str][source]

Parse a leading printf sign from a format_spec.

Returns

The sign that should be used. str: The remaining format_spec.

Return type

Sign

pyppin.text.sign.format_sign(formatted_unsigned: str, sign_mode: Sign, is_negative: bool) str[source]

Apply a Sign to a formatted number.

Parameters
  • formatted_unsigned – The number as rendered, not including any sign information. (i.e., a rendering of the absolute value of the number)

  • sign_mode – How signs should be attached to the number.

  • is_negative – Whether the number is negative.

Returns

The number formatted with the correct sign.