For a simple string input, pprint would be expected to return an output similar to print. However, the functionality differs ### Code: import time from pprint import pprint start = time.time() time.sleep(0.5) object_made = time.time() time.sleep(0.5) done = time.time() time.sleep(0.5) shown = time.time() pprint( f"Time to create object: {object_made - start}s\n" + f"Time to insert 100000 rows: {done - object_made}s\n" + f"Time to retrieve 100000 rows: {shown - done}s\n" ) ### Output Received: ('Time to create object: 0.5010814666748047s\n' 'Time to insert 100000 rows: 0.5010972023010254s\n' 'Time to retrieve 100000 rows: 0.501101016998291s\n') ### Expected Output: Time to create object: 0.5010814666748047s Time to insert 100000 rows: 0.5010972023010254s Time to retrieve 100000 rows: 0.501101016998291s
if pprint is called without parameters, it returns a TypeError >>> pprint() Traceback (most recent call last): File "", line 1, in TypeError: pprint() missing 1 required positional argument: 'object' it would be beneficial however to return an empty string or a new line character instead. An erroneous call would generate an unnecessary run-time error in a huge script
pprint.pprint is not designed to be a drop-in replacement for print. At this point, we cannot break existing code to change how pprint works. I suggest you make a pprint.pprint wrapper that does what you want, or maybe subclass pprint.PrettyPrinter.