Python Glossary Русский

all Python 3pprintfunction

pprint.isreadable()

checks

Checks whether an object can be rebuilt with eval() from its pformat() representation; always False for recursive objects.

Syntax

pprint.isreadable(object)

It helps decide whether a structure can be saved as Python code — a config or a test fixture. Instances of ordinary classes and object() give False: their repr like <… object at 0x…> cannot be eval'ed. True does not make eval safe: only the shape of the representation is checked, not where the data came from; read such strings back with ast.literal_eval or json instead.

Examples

import pprint
print(pprint.isreadable({'a': [1, 2.5, None]}))  # → True
print(pprint.isreadable(object()))  # → False
loop = []
loop.append(loop)
print(pprint.isreadable(loop))  # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy