On 01.07.2011 02:12, Nick Coghlan wrote:
On Fri, Jul 1, 2011 at 3:22 AM, Georg Brandl email@example.com 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...
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 withdrawn.
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.
Well, apparently someone called "Guido van Rossum" wrote a C implementation of fnmatch once, that is now included in all sorts of software (and in PHP):