Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50415
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | alex23 <wuwei23@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Documenting builtin methods |
| Date | Thu, 11 Jul 2013 15:35:56 +1000 |
| Organization | A noiseless patient Spider |
| Lines | 23 |
| Message-ID | <krlft3$c66$1@dont-email.me> (permalink) |
| References | <mailman.4558.1373512579.3114.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 11 Jul 2013 05:30:11 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="8e3577991ddec96dc61a91c861d1ba1b"; logging-data="12486"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184kdq23zDkT/m5JB+qlY6w" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 |
| In-Reply-To | <mailman.4558.1373512579.3114.python-list@python.org> |
| Cancel-Lock | sha1:R6E9BwlRfiZH5JpDD4Pe+YpZhmM= |
| Xref | csiph.com comp.lang.python:50415 |
Show key headers only | View raw
On 11/07/2013 1:15 PM, Joshua Landau wrote:
> I have this innocent and simple code:
>
> from collections import deque
> exhaust_iter = deque(maxlen=0).extend
> exhaust_iter.__doc__ = "Exhaust an iterator efficiently without
> caching any of its yielded values."
>
> Obviously it does not work. Is there a way to get it to work simply
> and without creating a new scope (which would be a rather inefficient
> a way to set documentation, and would hamper introspection)?
I would just go with the most obvious approach:
def exhaust_iter(iter):
"""
Exhaust an iterator efficiently without caching
any of its yielded values
"""
deque(maxlen=0).extend(iter)
It's not going to be that inefficient unless you're calling it in a long
inner loop.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Documenting builtin methods Joshua Landau <joshua@landau.ws> - 2013-07-11 04:15 +0100
Re: Documenting builtin methods alex23 <wuwei23@gmail.com> - 2013-07-11 15:35 +1000
Re: Documenting builtin methods Steven D'Aprano <steve@pearwood.info> - 2013-07-11 06:06 +0000
Re: Documenting builtin methods Chris Angelico <rosuav@gmail.com> - 2013-07-11 17:06 +1000
Re: Documenting builtin methods Steven D'Aprano <steve@pearwood.info> - 2013-07-11 07:15 +0000
Re: Documenting builtin methods Chris Angelico <rosuav@gmail.com> - 2013-07-11 17:23 +1000
Re: Documenting builtin methods Joshua Landau <joshua@landau.ws> - 2013-07-12 00:11 +0100
Re: Documenting builtin methods alex23 <wuwei23@gmail.com> - 2013-07-12 13:43 +1000
Re: Documenting builtin methods Joshua Landau <joshua@landau.ws> - 2013-07-12 08:09 +0100
csiph-web