Documenting builtin methods
alex23
wuwei23 at gmail.com
Thu Jul 11 01:35:56 EDT 2013
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.
More information about the Python-list
mailing list