-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
pprint doesn't use all width #63304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
pprint not only adds indentation, but also increases right margin for nested items. >>> pprint.pprint([' '.join(str(i) for i in range(30))]*2)
['0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 '
'28 29',
'0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 '
'28 29']
>>> pprint.pprint([[[[[[[[[[[[' '.join(str(i) for i in range(30))]]]]]]]]]]]]*2)
[[[[[[[[[[[['0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 '
'21 22 23 24 25 26 27 28 29']]]]]]]]]]],
[[[[[[[[[[['0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 '
'21 22 23 24 25 26 27 28 29']]]]]]]]]]]] As you can see in second example there is a place for at least '21 22 23 ' at the right. In case of multiline representation of nested items pprint can reserve space only at the end of last line and continue inner lines to full width. |
Here is a patch. Without patch: >>> pprint.pprint([[[[[[[[[[0, 0, 0]]*3]]]]]]]], width=21)
[[[[[[[[[[0,
0,
0],
[0,
0,
0],
[0,
0,
0]]]]]]]]]] With patch: >>> pprint.pprint([[[[[[[[[[0, 0, 0]]*3]]]]]]]], width=21)
[[[[[[[[[[0, 0, 0],
[0, 0, 0],
[0,
0,
0]]]]]]]]]] |
Could anyone please make a review? |
Thank you Antoine for your review. But first variant of the patch doesn't affect an example at the top of this issue, it doesn't change string formatting. The second variant makes string formatting use all free space at the right. With the patch:
>>> pprint.pprint([' '.join(str(i) for i in range(30))]*2)
['0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 '
'29',
'0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 '
'29']
>>> pprint.pprint([[[[[[[[[[[[' '.join(str(i) for i in range(30))]]]]]]]]]]]]*2)
[[[[[[[[[[[['0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 '
'25 26 27 28 29']]]]]]]]]]],
[[[[[[[[[[['0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 '
'25 26 27 28 29']]]]]]]]]]]] Could you please make a review of new patch? |
Resolved conflicts with bpo-19104. |
New changeset 7a6671d491da by Serhiy Storchaka in branch 'default': |
New changeset 6d9520e2223f by Serhiy Storchaka in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: