repr2

Module Contents

repr2.repr2(obj, rmtrailing0=False)

Produces the string representation of obj using str(obj).

This function calls str(obj) to produce a string representation of obj. Thus, obj can be any type, so long as __str__ is defined for obj. Decimal objects add a trailing ‘.’ if not already in the string representation. Can optionally remove trailing 0 if rmtrailing0 is True (i.e. 1.0 -> 1.).

Parameters:
  • obj – Can be any type. repr2() will use obj’s built-in __str__ method to produce the string.

  • rmtrailing0 (bool) – Remove trailing 0s from decimal numbers if True. Defaults to False.

Returns:

The string representation for obj.

Return type:

str

Example usage:

>>> from repr2 import repr2
>>> repr2(1.0)
'1.0'
>>> from decimal import Decimal
>>> repr2(Decimal('1'))
'1.'
>>> repr2(Decimal('1.0'))
'1.0'
>>> repr2(1.0, rmtrailing0=True)
'1.'