LWN: Comments on "Improving pretty-printing in Python" https://lwn.net/Articles/815265/ This is a special feed containing comments posted to the individual LWN article titled "Improving pretty-printing in Python". en-us Tue, 07 Oct 2025 17:44:03 +0000 Tue, 07 Oct 2025 17:44:03 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Improving pretty-printing in Python https://lwn.net/Articles/815660/ https://lwn.net/Articles/815660/ divbzero <div class="FormattedComment"> I don’t have a strong opinion on this, but would note that the debate over a __pretty__ method seems to parallel the debate over a __json__ method. [1] [2]<br> <p> [1]: <a href="https://bugs.python.org/issue27362">https://bugs.python.org/issue27362</a><br> <p> [2]: <a href="https://mail.python.org/pipermail/python-ideas/2010-July/007811.html">https://mail.python.org/pipermail/python-ideas/2010-July/...</a><br> <p> __json__ has not gained traction, probably because JSON serialization can be application dependent and JSONDecoder already provides a flexible way to customize JSON serialization.<br> <p> __pretty__ seems even more in the eye of the beholder so I’m not surprised to see hesitant reactions to the idea.<br> </div> Sat, 21 Mar 2020 07:22:17 +0000 Improving pretty-printing in Python https://lwn.net/Articles/815381/ https://lwn.net/Articles/815381/ NYKevin <div class="FormattedComment"> If you want to do this "at the level of application I/O," I would tend to assume you'd just subclass reprlib.Repr and implement the repr_foo() method overrides. Since that's already in the standard library, I'm not sure I understand what they are proposing... Maybe you could add a fallback option where reprlib.Repr.repr1() dispatches to some dunder method on the object (with the expectation that the object call back into repr1() when it wants to format a subobject)? That seems messy, since I usually think of dunder methods as belonging to the language rather than the standard library. But there is precedent for this sort of thing (e.g. __copy__ and __deepcopy__), so I suppose it could work.<br> </div> Thu, 19 Mar 2020 01:19:02 +0000