When introspecting a #Python object, I sometimes use a comprehension to remove dunder method noise from dir(...) output:

>>> numbers = [2, 1, 3]
>>> public = [name for name in dir(numbers) if not name.startswith("_")]
>>> public
['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

This removes MANY underscore-prefixed methods:

>>> len(dir(numbers)) - len(public)
37

Anyone know if something like dir(..., public=True) has ever been proposed?

@treyhunner I'd go a stage further ...dir(..., public=True, pretty=True) ... where making the pretty arg True was the equivalent of pprint.pprint(dir(...)) ... I find scanning across lines harder than scanning down.

@shearichard dir() returns a list, so I don't think that would work unfortunatley.

But you might find the recently proposed PEP 813 interesting: https://discuss.python.org/t/pep-813-the-pretty-print-protocol/106242

PEP 813 - The Pretty Print Protocol

A couple of the elder statesmen are happy to announce PEP 813, a proposal to build-in optional pretty printing for print(), str.format(), and f-strings, and to define a protocol classes can implement to participate in and customize how their instances are pretty printed. Enjoy, and let the games begin!

Discussions on Python.org