Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74040
| 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 | <python.list@tim.thechases.com> |
| 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 <python.list@tim.thechases.com> |
| 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 | <mailman.11547.1404665036.18130.python-list@python.org> <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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11550.1404671011.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How do you use `help` when write your code Shiyao Ma <i@introo.me> - 2014-07-07 00:36 +0800
Re: How do you use `help` when write your code Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-06 17:52 +0000
Re: How do you use `help` when write your code Tim Chase <python.list@tim.thechases.com> - 2014-07-06 13:22 -0500
Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-06 14:48 -0400
Re: How do you use `help` when write your code Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 11:48 -0700
Re: How do you use `help` when write your code Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-06 19:58 +0100
Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-06 15:15 -0400
Re: How do you use `help` when write your code Chris Angelico <rosuav@gmail.com> - 2014-07-07 08:54 +1000
Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-06 20:52 -0400
Re: How do you use `help` when write your code Chris Angelico <rosuav@gmail.com> - 2014-07-07 13:06 +1000
Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-07 07:22 -0400
Re: How do you use `help` when write your code Chris Angelico <rosuav@gmail.com> - 2014-07-07 21:36 +1000
Re: How do you use `help` when write your code Cameron Simpson <cs@zip.com.au> - 2014-07-07 11:51 +1000
csiph-web