Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8642
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'attributes': 0.05; 'python)': 0.05; 'see:': 0.07; 'python': 0.08; 'namespace': 0.09; 'respond.': 0.09; 'wrote:': 0.15; '"and': 0.16; 'anyways,': 0.16; 'blurb': 0.16; 'constants': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'subject:() ': 0.16; 'subject:function': 0.16; 'cc:addr:python- list': 0.16; 'pm,': 0.16; '>>>': 0.16; '(i.e.': 0.17; 'ignore': 0.21; 'cc:2**0': 0.21; 'filter': 0.22; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'welcome.': 0.23; '(or': 0.25; 'function': 0.26; "i'm": 0.27; 'pass': 0.28; 'raise': 0.28; 'objects': 0.28; 'cc:addr:python.org': 0.30; 'invoke': 0.30; 'recall': 0.30; 'version': 0.30; 'seem': 0.31; 'header:User- Agent:1': 0.34; 'improvements': 0.35; 'replacement': 0.35; 'regular': 0.36; 'enhanced': 0.37; 'some': 0.37; 'brief': 0.37; 'could': 0.37; 'subject:: ': 0.38; 'steven': 0.38; 'something': 0.38; 'comments': 0.38; 'allows': 0.39; "there's": 0.39; "i'd": 0.40; 'where': 0.40; 'methods': 0.40; 'link': 0.63; 'designed': 0.63; 'here': 0.66; '11:29': 0.84; 'by,': 0.84; 'methods?': 0.84; 'sourced': 0.91; 'that),': 0.91 |
| Date | Fri, 01 Jul 2011 12:20:57 -0500 |
| From | Tim Chase <python.list@tim.thechases.com> |
| User-Agent | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 |
| MIME-Version | 1.0 |
| To | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
| Subject | Re: Enhanced dir() function |
| References | <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> |
| In-Reply-To | <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| 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-Source | |
| X-Source-Args | |
| X-Source-Dir | |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.546.1309543383.1164.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1309543383 news.xs4all.nl 21779 [2001:888:2000:d::a6]:57372 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8642 |
Show key headers only | View raw
On 06/30/2011 11:29 PM, Steven D'Aprano wrote:
> The dir() function is designed for interactive use, inspecting objects for
> the names of attributes and methods.
>
> Here is an enhanced version that allows you to pass a glob to filter the
> names you see:
>
> Comments and improvements welcome.
Having not seen any other comments on it fly by, I thought I'd
respond. While in general I like the idea, I'm not sure when I'd
go to the effort of bringing the function into my namespace when
I could just do something like
>>> [s for s in dir(...) if test_of_interest(s)]
If it came in as an effortless (i.e. O(1) where I do it once and
never again; not an O(n) where n=the number of times I invoke
Python) default replacement for dir(), I'd reach for it a lot
more readily. I seem to recall there's some environment-var or
magic file-name that gets sourced on every startup.
I use the list-comp version on a regular basis:
# implementation of which magic methods?
[s for s in dir(foo) if s.startswith('__') and s.endswith('__')]
# ignore magic methods
[s for s in dir(foo) if not (s.startswith('__') and
s.endswith('__'))]
# constants
[s for s in dir(foo) if s.isupper()]
# keywording
[s for s in dir(foo) if 'bar' in s.lower()]
Anyways, even if it just includes a brief blurb about "and this
is how you get it automatically in every Python session" (or a
link to the docs on how to do that), it would raise it from "meh"
to "nifty".
-tim
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Enhanced dir() function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-01 14:29 +1000
Re: Enhanced dir() function Tim Chase <python.list@tim.thechases.com> - 2011-07-01 12:20 -0500
Re: Enhanced dir() function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-02 04:32 +1000
Re: Enhanced dir() function rantingrick <rantingrick@gmail.com> - 2011-07-12 14:46 -0700
Re: Enhanced dir() function Chris Angelico <rosuav@gmail.com> - 2011-07-13 14:20 +1000
Re: Enhanced dir() function Ethan Furman <ethan@stoneleaf.us> - 2011-07-01 11:40 -0700
Re: Enhanced dir() function Ethan Furman <ethan@stoneleaf.us> - 2011-07-12 14:19 -0700
Re: Enhanced dir() function rantingrick <rantingrick@gmail.com> - 2011-07-12 14:38 -0700
csiph-web