[Python-ideas] dir with a glob?

Nick Coghlan ncoghlan at gmail.com
Fri Jul 1 04:15:08 CEST 2011


On Fri, Jul 1, 2011 at 10:27 AM, Ben Finney <ben+python at benfinney.id.au> wrote:
>>>> import scipy
>>>> [a for a in dir(scipy.fft) if a.startswith("f")]
> ['func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']

See Steven's quote about the reason for dir's very existence (i.e. as
a convenience function). There's no real comparison from a usability
point of view between the above and "dir(scipy.fft, 'f*')"

fnmatch.filter(dir(scipy.fft), "f*") is even simpler than the list
comprehension, but still no match for the builtin version.

However, as I mentioned in my other email, the dependency problem
means this is likely to be harder to implement than it first looks, so
the next step if for someone that is sufficiently interested to create
a patch.

Cheers,
Nick.

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



More information about the Python-ideas mailing list