Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82298

Re: Python Iterables struggling using map() built-in

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
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; 'example:': 0.03; 'syntax': 0.04; 'explicitly': 0.05; 'inspired': 0.05; 'subject:Python': 0.06; 'pride': 0.07; 'string': 0.09; 'attributes': 0.09; 'feature,': 0.09; 'function,': 0.09; 'methods,': 0.09; 'subject:using': 0.09; 'python': 0.11; '"some': 0.16; 'algorithm.': 0.16; 'arbitrarily.': 0.16; 'attributes,': 0.16; 'awesome.': 0.16; 'callable': 0.16; 'chained': 0.16; 'downside': 0.16; 'exist.': 0.16; 'ides': 0.16; 'likewise': 0.16; 'namespace.': 0.16; 'ought': 0.16; 'rejected.': 0.16; 'attach': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; 'proposed': 0.22; 'alternate': 0.24; 'necessary.': 0.24; 'versions': 0.24; '&gt;': 0.26; 'mention': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'am,': 0.29; 'properties': 0.29; 'dec': 0.30; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'serve': 0.31; 'apparently': 0.31; "d'aprano": 0.31; 'doc': 0.31; 'existence': 0.31; 'steven': 0.31; 'class': 0.32; 'another': 0.32; 'could': 0.34; 'problem': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'library.': 0.36; 'module.': 0.36; 'useful': 0.36; 'similar': 0.36; 'being': 0.38; 'e.g.': 0.38; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'that,': 0.38; 'though,': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'simply': 0.61; 'first': 0.61; 'making': 0.63; 'such': 0.63; 'more': 0.64; 'nobody': 0.68; 'completion': 0.78; 'median': 0.84; 'object:': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=v0z5OEkbd9XBQ2wZRcNSePCsAtOnVIrseIfVbFInHsc=; b=k7QJBWosaYrc+ubncUJPduaXo9kRp2BO3H9/wfy8JZWTPgUjS+uuXp9OZVdbBiuH/3 kt9PN7XaH+wN7ZsGldo7YA/oa458lX894T9xDNkByZ+r32KHFgY65iRh9ayN7E0cbfw2 KpYLbBHH3FEp6kIrzijZkJJcoBHezOFv7QE4niYJcII+HiXHorpntbcVzPKtMx/Co6FM yvHm/RFnlavXI2uXiUtTjy2JOHo530OJdXEk0SDajg5MZnqb98i+qQ1eQz8qCQ9olmZF fXJcEHMD/Kg8m+au4ygBcHC8EbD3rk0PJBZQlsitLPvJL8CntXUDLiWm0qnJorAw6qzk Sn5A==
X-Received by 10.66.240.71 with SMTP id vy7mr8697769pac.89.1418230056309; Wed, 10 Dec 2014 08:47:36 -0800 (PST)
MIME-Version 1.0
In-Reply-To <54881159$0$2817$c3e8da3$76491128@news.astraweb.com>
References <004e01d01173$e1641c10$a42c5430$@gmail.com> <m61roh$i5m$1@ger.gmane.org> <CALwzid=79=i3Sez3fQYV7xU2bEAL4_ohPqxhuYj59Y5ihXk1Zg@mail.gmail.com> <mailman.16685.1417976998.18130.python-list@python.org> <5484e3d8$0$13013$c3e8da3$5496439d@news.astraweb.com> <roy-3F4751.19122007122014@news.panix.com> <54866372$0$12991$c3e8da3$5496439d@news.astraweb.com> <m65vrc$j0t$1@ger.gmane.org> <mailman.16776.1418155635.18130.python-list@python.org> <54878f8a$0$13010$c3e8da3$5496439d@news.astraweb.com> <roy-0FD505.21442409122014@news.panix.com> <54881159$0$2817$c3e8da3$76491128@news.astraweb.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 10 Dec 2014 09:46:55 -0700
Subject Re: Python Iterables struggling using map() built-in
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=047d7b15a47bb75a510509df6a27
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16818.1418230065.18130.python-list@python.org> (permalink)
Lines 92
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418230065 news.xs4all.nl 2945 [2001:888:2000:d::a6]:47320
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82298

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Wed, Dec 10, 2014 at 2:24 AM, Steven D'Aprano <steve@pearwood.info>
wrote:
>
> Example: In the statistics module in Python 3.4, I added a `median`
> function to calculate the median by the traditional schoolbook algorithm.
> But that's only one out of a number of ways to calculate medium, and
> inspired by similar syntax from R I proposed adding additional methods to
> that `median` object:
>
>     median.low(alist)
>     median.high(alist)
>
> etc. We all know that functions are first class objects with attributes
> and methods, they have a __dict__ so you can attach per-function data to
> them. And there's the last line of the Zen, about namespaces being
> awesome. Every instance with a __dict__ is a namespace.
>
> This ought to be a no-brainer, but apparently nobody has any experience
> with callable attributes attached to instances:
>
>     math.sin(x)
>     "some string".split(s)
>
> We make it a point of pride that functions in Python are not just first
> class values but that they are objects with attributes and methods and a
> per-instance __dict__. But when somebody proposes making use of that, it
> is rejected. Not that I'm bitter :-)

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 defeats the dir() function for that module.
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 or the standard median function. Thirdly, IDEs with
code completion features may simply fail to notice that these alternate
versions of the function exist. For these reasons I think that this is an
anti-pattern and is best avoided in the standard library. Having to type _
instead of . is only one extra key stroke.

Now if there were an established pattern to such function attributes, e.g.
if f.len(parrots) was a standard alternative to len(f(parrots)) for
functions that return sequences, then that could be a useful feature,
especially if such properties could be chained arbitrarily. But one-offs
like median.low would only serve to make the function more difficult to
find than necessary.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-08 05:29 +1100
  Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-08 10:33 +1100
    Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-08 10:50 +1100
      Re: Python Iterables struggling using map() built-in Roy Smith <roy@panix.com> - 2014-12-07 19:27 -0500
        Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-08 11:35 +1100
          Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve@pearwood.info> - 2014-12-08 09:40 +0000
            Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-08 20:50 +1100
            Re: Python Iterables struggling using map() built-in Roy Smith <roy@panix.com> - 2014-12-08 19:02 -0500
    Re: Python Iterables struggling using map() built-in Roy Smith <roy@panix.com> - 2014-12-07 19:12 -0500
      Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-08 11:34 +1100
        Re: Python Iterables struggling using map() built-in Roy Smith <roy@panix.com> - 2014-12-07 19:45 -0500
          Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-08 12:00 +1100
          Re: Python Iterables struggling using map() built-in MRAB <python@mrabarnett.plus.com> - 2014-12-08 03:09 +0000
      Re: Python Iterables struggling using map() built-in Terry Reedy <tjreedy@udel.edu> - 2014-12-07 19:38 -0500
        Re: Python Iterables struggling using map() built-in Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-12-08 18:06 +1300
      Re: Python Iterables struggling using map() built-in Ned Batchelder <ned@nedbatchelder.com> - 2014-12-07 20:06 -0500
      Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-09 13:50 +1100
        Re: Python Iterables struggling using map() built-in Terry Reedy <tjreedy@udel.edu> - 2014-12-09 00:03 -0500
          Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve@pearwood.info> - 2014-12-09 06:40 +0000
        Re: Python Iterables struggling using map() built-in Terry Reedy <tjreedy@udel.edu> - 2014-12-09 15:06 -0500
          Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-10 11:10 +1100
            Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-10 11:20 +1100
            Re: Python Iterables struggling using map() built-in Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-12-10 00:24 +0000
            Re: Python Iterables struggling using map() built-in Roy Smith <roy@panix.com> - 2014-12-09 21:44 -0500
              Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve@pearwood.info> - 2014-12-10 09:24 +0000
                Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-10 20:32 +1100
                Re: Python Iterables struggling using map() built-in Marko Rauhamaa <marko@pacujo.net> - 2014-12-10 12:58 +0200
                Re: Python Iterables struggling using map() built-in Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-10 09:46 -0700
                Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve@pearwood.info> - 2014-12-11 04:01 +0000
                Re: Python Iterables struggling using map() built-in Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-11 15:00 -0700
                Re: Python Iterables struggling using map() built-in Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-12 10:28 +1100
                Re: Python Iterables struggling using map() built-in Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-11 16:57 -0700
                Re: Python Iterables struggling using map() built-in Roy Smith <roy@panix.com> - 2014-12-11 20:55 -0500
                Re: Python Iterables struggling using map() built-in Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-12 00:36 -0700
                Re: Python Iterables struggling using map() built-in Chris Angelico <rosuav@gmail.com> - 2014-12-12 11:44 +1100
                Re: Python Iterables struggling using map() built-in Terry Reedy <tjreedy@udel.edu> - 2014-12-10 12:48 -0500
                Re: Python Iterables struggling using map() built-in Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-10 13:32 -0700
                Re: Python Iterables struggling using map() built-in Terry Reedy <tjreedy@udel.edu> - 2014-12-10 23:17 -0500
    Re: Python Iterables struggling using map() built-in Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-12-08 18:00 +1300

csiph-web