Popular Python recipes tagged "dir"http://code.activestate.com/recipes/langs/python/tags/dir/2011-07-01T04:03:46-07:00ActiveState Code RecipesEnhancing dir() with globs (Python) 2011-07-01T04:03:46-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577774-enhancing-dir-with-globs/ <p style="color: grey"> Python recipe 577774 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/dir/">dir</a>, <a href="/recipes/tags/filter/">filter</a>, <a href="/recipes/tags/glob/">glob</a>, <a href="/recipes/tags/globbing/">globbing</a>). </p> <p>dir() is useful for interactively exploring the attributes and methods of objects at the command line. But sometimes dir() returns a lot of information:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; len(dir(decimal.Decimal)) # too much information! 137 </code></pre> <p>It can be helpful to filter the list of names returned. This enhanced version of dir does exactly that, using simple string globbing:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; dir(decimal.Decimal, '*log*') # just attributes with "log" in the name ['_fill_logical', '_islogical', '_log10_exp_bound', 'log10', 'logb', 'logical_and', 'logical_invert', 'logical_or', 'logical_xor'] </code></pre>