Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'argument': 0.05; 'explicitly': 0.05; 'subject:Python': 0.06; 'class,': 0.07; 'string': 0.09; 'attributes': 0.09; 'constructor': 0.09; 'exist,': 0.09; 'function,': 0.09; 'instances.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'jan': 0.12; 'added.': 0.16; 'attributes,': 0.16; 'dict': 0.16; 'downside': 0.16; 'evaluates': 0.16; 'exist.': 0.16; 'ides': 0.16; 'iterable': 0.16; 'itertools': 0.16; 'likewise': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'value=none,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'module': 0.19; 'value.': 0.19; 'written': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'alternate': 0.24; 'apply.': 0.24; 'versions': 0.24; 'mention': 0.26; 'recognized': 0.26; 'values': 0.27; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'code': 0.31; 'doc': 0.31; 'existence': 0.31; 'keys': 0.31; 'lists': 0.32; 'probably': 0.32; 'another': 0.32; 'core': 0.34; 'problem': 0.35; 'classes': 0.35; 'equal': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'idle': 0.36; 'instances': 0.36; 'module.': 0.36; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'chain': 0.60; 'ian': 0.60; 'new': 0.61; 'simply': 0.61; 'further': 0.61; 'making': 0.63; 'show': 0.63; 'taking': 0.65; 'believe': 0.68; 'increase': 0.74; 'completion': 0.78; 'dict.': 0.84; 'received:fios.verizon.net': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python Iterables struggling using map() built-in Date: Wed, 10 Dec 2014 12:48:06 -0500 References: <004e01d01173$e1641c10$a42c5430$@gmail.com> <5484e3d8$0$13013$c3e8da3$5496439d@news.astraweb.com> <54866372$0$12991$c3e8da3$5496439d@news.astraweb.com> <54878f8a$0$13010$c3e8da3$5496439d@news.astraweb.com> <54881159$0$2817$c3e8da3$76491128@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418233709 news.xs4all.nl 2856 [2001:888:2000:d::a6]:48877 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 2696039374 X-Received-Bytes: 6313 Xref: csiph.com comp.lang.python:82304 On 12/10/2014 11:46 AM, Ian Kelly wrote: > I don't particularly have a problem with functions having attributes, > e.g. I think itertools.chain.from_iterable is just peachy. There is a > downside though, which is that making those functions attributes of > another function rather than of the module Itertools.chain is a class, not a function. Chain.from_iterable is an *alternate constructor* for instances of the class, just as dict.fromkeys is an alternate constructor for dict instances. It is true that if itertools were written in python, chain and the other classes would likely be written as generator functions, so tha analogy would not apply. > defeats the dir() function for that module. And it is also true that dir(__builtins__) does not show dict.fromkeys. > 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. help(dict) | fromkeys(iterable, value=None, /) from builtins.type | Returns a new dict with keys from iterable and values equal to value. > 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 None of the above is to say that alternate constructors for classed are not a bit awkward. I believe this was recognized when dict.fromkeys was added. But it was considered less awkward than the alternatives: 1. do not add the functionality; 2. further overload the main (__init__) constructor; 3. add a independent function. Anyway, they exist, are an accepted pattern among core devs, and will probably increase in number. -- Terry Jan Reedy