I notice that I can do this and get away with it, at least at first glance:
from pprint import pprint as print
Convenient. But I have a bad feeling about this. What sort of grue is going to eat me if I try this in a nontrivial program?
Beware that pprint
is meant for dumping Python data structures, as it always prints the output of the __repr__
method of each object in the data structures pass to it, and is therefore not very suitable as a replacement to print
:
>>> b = '''Hemingway's "The Old Man and the Sea"'''
>>> print(b)
Hemingway's "The Old Man and the Sea"
>>> pprint(b)
'Hemingway\'s "The Old Man and the Sea"'
So if you replace the built-in print
function with pprint
and want to print some readable messages, you would find the output looking funny with all these unintended quotes and escape sequences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With