[Python-ideas] Allow filtered dir built in

Rob Cliffe rob.cliffe at btinternet.com
Thu Jun 14 17:27:48 EDT 2018


On 14/06/2018 10:27, Steve Barnes wrote:
> Currently when working with interactive sessions using the dir() or
> dir(module) built in is incredibly useful for exploring what
> functionality is available in a module. (Especially the regrettable
> libraries or modules that add really valuable functionality but have no
> or limited docstrings).
>
> However I often find that when a module adds a lot of functions I need
> to filter those entries to be able to find the one that I need, e.g.:
>
>   >>> import mpmath
>   >>> dir(mpmath)  # This produces 390+ lines of output but
>   >>> for name in dir(mpmath):
> ..    if 'sin' in name:
> ..        print(name)  # gives me a mere 13 to consider as candidates
>
> What I would really like to do is:
>   >>> dir(mpmath.*sin*)
I have also hit this use case.  But it never seemed like much of a 
hardship to write
     [  x for x in dir(SomeObject) if    <some condition on x>    ]
Rob Cliffe


More information about the Python-ideas mailing list