[Python-ideas] dir with a glob?

Nick Coghlan ncoghlan at gmail.com
Fri Jul 1 02:12:37 CEST 2011

On Fri, Jul 1, 2011 at 3:22 AM, Georg Brandl <g.brandl at gmx.net> wrote:
> On 30.06.2011 18:31, Steven D'Aprano wrote:
>> dir is a convenience function, designed for interactive use. The docs
>> make it explicit:
>> [quote]
>> Because dir() is supplied primarily as a convenience for use at an
>> interactive prompt, it tries to supply an interesting set of names more
>> than it tries to supply a rigorously or consistently defined set of names...
>> http://docs.python.org/library/functions.html#dir
>> Given that, I see no downside to making dir more convenient for
>> interactive use. That's what it's for.
> I agree.  I often am looking for a specific member that I know exists, but
> don't recall the exact name (and in particular, not what the name starts
> with: at least dir() output is sorted).  Searching through one screenful
> of members isn't pretty.
> So, +1 for the second argument.

Yep, I found Steven's reply quite persuasive, so consider my objection

And for interactive prompt usage, simple glob-style matching is a
better choice than the more powerful re.

However, this now needs a tracker issue and a patch - as a builtin
that may legitimately be used before the import machinery is fully
initialised, it isn't really acceptable for dir() to depend on the
fnmatch module just for this feature, so implementing this isn't going
to be quite as easy as it might otherwise be.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list