| CARVIEW |
Select Language
HTTP/2 200
server: nginx
date: Tue, 30 Dec 2025 16:16:26 GMT
content-type: text/html; charset=utf-8
expires: Tue, 30 Dec 2025 16:16:25 GMT
cache-control: no-cache
x-frame-options: sameorigin
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-permitted-cross-domain-policies: none
content-encoding: gzip
x-clacks-overhead: GNU Terry Pratchett
strict-transport-security: max-age=315360000; includeSubDomains; preload
Issue 45611: pprint - low width overrides depth folding - Python tracker
- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
Issue45611
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2021-10-26 07:40 by iansedano, last changed 2022-04-11 14:59 by admin.
| Messages (1) | |||
|---|---|---|---|
| msg405027 - (view) | Author: Ian Currie (iansedano) | Date: 2021-10-26 07:40 | |
Reproducible example: >>> from pprint import pprint >>> data = [["aaaaaaaaaaaaaaaaaa"],[2],[3],[4],[5]] >>> pprint(data) [["aaaaaaaaaaaaaaaaaa"], [2], [3], [4], [5]] >>> pprint(data, depth=1) [[...], [...], [...], [...], [...]] >>> pprint(data, depth=1, width=7) [[...], [...], [...], [...], [...]] >>> pprint(data, depth=1, width=6) [['aaaaaaaaaaaaaaaaaa'], [2], [3], [4], [5]] The depth "folds" everything deeper than 1 level. Then if you lower the width of the output enough, what was once on one line, will now be split by newlines. The bug is, if you lower the width below seven characters. Which is the length of `[[...],` It seems to override the `depth` parameter and print the everything with no folding. This is true of deeply nested structures too. Expected behavior: for the folding `...` to remain. Why put the width so low? I came across this because of the behavior of `compact`: By default, if a data structure can fit on one line, it will be displayed on one line. `compact` only affects sequences that are longer than the given width. **There is no way to force compact as False for short items**, so as to make sure all items, even short ones, appear on their own line. [1,2,3] - will always appear on its own line, there is no way to make it appear like: [1, 2, 3] The only way is by setting a very low width. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:51 | admin | set | github: 89774 |
| 2021-10-26 07:40:20 | iansedano | create | |
