Issue36705
Created on 2019-04-23 12:47 by gavin, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg340720 - (view) | Author: Gavin D'souza (gavin) | Date: 2019-04-23 12:47 | |
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
|
|||
| msg340721 - (view) | Author: Gavin D'souza (gavin) | Date: 2019-04-23 12:54 | |
if pprint is called without parameters, it returns a TypeError >>> pprint() Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 |
|||
| msg340723 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2019-04-23 13:17 | |
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. |
|||
| msg340725 - (view) | Author: Fred Drake (fdrake) ![]() |
Date: 2019-04-23 13:26 | |
Eric nailed it; pprint was not designed as a replacement for print, and was never intended to serve that purpose. Rejecting as out of scope. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:14 | admin | set | github: 80886 |
| 2019-04-23 13:26:24 | fdrake | set | status: open -> closed resolution: rejected messages: + msg340725 stage: resolved |
| 2019-04-23 13:17:37 | eric.smith | set | nosy:
+ eric.smith messages: + msg340723 |
| 2019-04-23 12:54:52 | gavin | set | messages: + msg340721 |
| 2019-04-23 12:47:49 | gavin | create | |
