Python Iterables struggling using map() built-in

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 10 15:32:28 EST 2014


On Wed, Dec 10, 2014 at 10:48 AM, Terry Reedy <tjreedy at udel.edu> wrote:
>> Likewise the generated help for the help() function,
>> unless care is taken to explicitly mention the existence of those
>> functions in either the doc string for the module
>
>
> help(it.chain) lists
>  |  from_iterable(...) from builtins.type
>  |      chain.from_iterable(iterable) --> chain object
>  |
>  |      Alternate chain() contructor taking a single iterable argument
>  |      that evaluates lazily.

As you point out, chain is a class, not a function. When you invoke help()
on a function, it lists the members, of which a static alternate
constructor would be one. Try it with a function, though:

>>> import statistics
>>> statistics.median.low = statistics.median_low
>>> help(statistics.median)
Help on function median in module statistics:

median(data)
    Return the median (middle value) of numeric data.

    When the number of data points is odd, return the middle data point.
    When the number of data points is even, the median is interpolated by
    taking the average of the two middle values:

    >>> median([1, 3, 5])
    3
    >>> median([1, 3, 5, 7])
    4.0

It only prints out the doc string, nothing about the attributes. So the doc
string for median would need to explicitly document the existence of
median.low and median.high in addition to its own usage.

>> Thirdly, IDEs with code completion features may simply fail to
>> notice that these alternate versions of the function exist.
>
> I don't know what you mean here.  In Idle
> >>> it.chain.  --> completion box with from_iterable
> >>> dict.   --> completion box that includes fromkeys

So Idle gets it right. At least for static methods of classes, which isn't
very surprising. Does it complete a function attribute of a function? I
don't have it installed to test.

Having used Komodo IDE for a number of years and been occasionally
frustrated by its code completion, it would not surprise me in the least if
it failed to pull attributes of functions into its completion database.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141210/44e423aa/attachment.html>


More information about the Python-list mailing list