On Thu, Jun 30, 2011 at 8:29 AM, Ben Finney email@example.com wrote:
Sturla Molden firstname.lastname@example.org writes:
Often when exploring an object with the 'dir' function, particularly in large packages like SciPy, I find that I need to filter the outout.
We have list comprehensions and generator expressions to filter a sequence, and I suspect they would serve you well for this purpose.
The problem is that dir is generally used on a live section, and a list comprehension to filter dir results is way to verbose to type when you need it.
Since a dir reminds me of a dos 'dir' or linux 'ls', a glob feels like the most natural to use.
For example, none of these would work:
dir(sp.fft.i*) # syntax error
What would you expect this to return? The ‘dir’ function is specifically for inspecting *one* object. Do you just want all the attributes of all the matching objects mixed up together, or what?
I believe a new dir functions is needed, or a change in the behviour of the current version.
This is ‘python-ideas’. What is your idea for the desired behaviour?
What about using a list comprehension or generator expression to get what you want?
I believe a second parameter to dir, being a glob filter string, would be fine. Being able to type:
dir (gtk.Window, "set*")
, for example instead of
[attrib for attrib in dir(gtk.Window) if attrib.startswith("set")]
would be indeed a good thing to have.
-- \ “A learning experience is one of those things that say, “You | `\ know that thing you just did? Don't do that.”” —Douglas Adams, | _o__) 2000-04-05 | Ben Finney
Python-ideas mailing list Pythonemail@example.com http://mail.python.org/mailman/listinfo/python-ideas