Can I have pretty printed data output as in pprint.pprint
(new lines, indentation), but also shortened lists as in reprlib.repr
at the same time?
An ugly hack seems to be pprint(eval(reprlib.repr(data)))
, but is there a better way?
Can I have pretty printed data output as in pprint.pprint
(new lines, indentation), but also shortened lists as in reprlib.repr
at the same time?
An ugly hack seems to be pprint(eval(reprlib.repr(data)))
, but is there a better way?
You can change the way an object is printed by overriding the __repr__()
method on its class.
Python will allow you to override the repr of any class, so use it with care.