Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'much!': 0.05; 'nicely': 0.07; 'subject:code': 0.07; 'subject:help': 0.08; 'string': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; "'environ',": 0.16; '-tkc': 0.16; 'argument,': 0.16; 'callable': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'subject:when': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'tend': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; "d'aprano": 0.31; 'steven': 0.31; 'version': 0.36; 'charset:us-ascii': 0.36; 'too': 0.37; 'list': 0.37; 'filter': 0.38; 'even': 0.60; 'more': 0.64; 'subject:your': 0.76; 'received:50.22': 0.84; 'subject:you': 0.87; 'to:none': 0.92 Date: Sun, 6 Jul 2014 13:22:30 -0500 From: Tim Chase Cc: python-list@python.org Subject: Re: How do you use `help` when write your code In-Reply-To: <53b98cf2$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <53b98cf2$0$29985$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404671011 news.xs4all.nl 2924 [2001:888:2000:d::a6]:47096 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74040 On 2014-07-06 17:52, Steven D'Aprano wrote: > I have a monkey-patched version of dir() which takes a second > argument, a glob, to filter the list of names returned: > > py> len(dir(os)) # Too much! > 312 > py> dir(os, 'env') > ['_putenv', '_unsetenv', 'environ', 'environb', 'getenv', > 'getenvb', 'putenv', 'supports_bytes_environ', 'unsetenv'] > py> dir(os, 'env*') > ['environ', 'environb'] And for those of us that don't have Steven's monkey-patched dir() call, I tend to do it with a list comprehension: >>> [s for s in dir(obj) if 'env' in s] {output here} This works nicely for even more complex tests: >>> [s for s in dir(obj) if not s.startswith('_')] {list of public properties/methods} >>> [s for s in dir(obj) if callable(getattr(obj, s))] {list of callable attributes} >>> [s for s in dir(obj) if isinstance(getattr(obj, s), basestring)] {list of string attributes} -tkc