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


Groups > comp.lang.python > #90181

Re: functions, optional parameters

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.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 <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'context': 0.07; 'attributes': 0.09; 'created,': 0.09; 'executed': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; '"code': 0.16; '1:48': 0.16; 'closures': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'read-only.': 0.16; 'subject:parameters': 0.16; 'time"': 0.16; 'underlying': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'cc:addr:python.org': 0.22; 'compilation': 0.24; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'function': 0.29; 'am,': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'objects': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'i.e.': 0.36; 'object,': 0.36; 'two': 0.37; 'aside': 0.39; 'ian': 0.60; 'between': 0.67; 'default': 0.69; '2015': 0.84; 'compiling': 0.84; 'distinguish': 0.84; 'played': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=7g6ge2fN8XCfMgyWVAUMec5ZwuwAg+EhIiEJr52dARE=; b=b46l172MddC8i6IPvctWKeLYlCo/DICWxAsrPwNT990oSnR0dnTxAL99IMMEX4g6H5 lBApZHtPwJbmXwKgwMasJ0QhSXdXIQgi3EsfS/0OZqaghJJ0yLZoDuOjEeR6Ccf6mRcU IQzBhkjmyXZeF3ggNk/cY8pVuZQr63Cf4bbuTLrbyI7oRf52gqN7oUiV+7rQl1Qyx6LZ 4rOip/3CUARsWnt+6iCPQ6doQ6vWp7Pc/M84AGzoTbNtkaIEBVrQER9cPZaNyU9Se1PB LJfT8l30eG0ZGUtxrtEh3Sz7OHHIFIX0D2ZyJpfOD89X22jTToaM+vktfUQc8KzfYes7 DrrA==
MIME-Version 1.0
X-Received by 10.42.43.199 with SMTP id y7mr4983273ice.12.1431100963115; Fri, 08 May 2015 09:02:43 -0700 (PDT)
In-Reply-To <CALwzidnkFF3DZws_5q=O6g9DFyFD5yK=BvHY2DtRoCVnZYLdyw@mail.gmail.com>
References <72lu1cxvmg.ln2@news.c0t0d0s0.de> <554cd511$0$12979$c3e8da3$5496439d@news.astraweb.com> <CALwzidnkFF3DZws_5q=O6g9DFyFD5yK=BvHY2DtRoCVnZYLdyw@mail.gmail.com>
Date Sat, 9 May 2015 02:02:42 +1000
Subject Re: functions, optional parameters
From Chris Angelico <rosuav@gmail.com>
Cc Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.256.1431100965.12865.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431100965 news.xs4all.nl 2950 [2001:888:2000:d::a6]:46601
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90181

Show key headers only | View raw


On Sat, May 9, 2015 at 1:48 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On May 8, 2015 9:26 AM, "Steven D'Aprano"
> <steve+comp.lang.python@pearwood.info> wrote:
>>
>> Do you think that Python will re-compile the body of the function every
>> time
>> you call it? Setting the default is part of the process of compiling the
>> function.
>
> To be a bit pedantic, that's not accurate. The default is evaluated when the
> function object is created, i.e. when the def statement is executed at
> runtime, not when the underlying code object is compiled.

Aside from constructing two closures in the same context and proving
that their __code__ attributes point to the same object, is there any
way to distinguish between "code object compilation time" and "def
execution time"? I just played around with it, and as far as I can
tell, code objects are completely read-only.

ChrisA

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


Thread

functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 13:59 +0200
  Re: functions, optional parameters Rustom Mody <rustompmody@gmail.com> - 2015-05-08 05:09 -0700
    Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 14:36 +0200
  Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-08 22:39 +1000
    Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 14:57 +0200
  Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 01:24 +1000
    Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-09 02:02 +1000
      Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 03:36 +1000
        Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-09 03:49 +1000
          Re: functions, optional parameters Mel Wilson <mwilson@the-wire.com> - 2015-05-08 18:49 +0000
          Re: functions, optional parameters Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-09 13:41 +1200
            Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-09 12:05 +1000
              Re: functions, optional parameters Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-09 19:27 +1200
          Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 12:52 +1000
    Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 03:26 +1000
    Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 17:50 +0200
      Re: functions, optional parameters Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-09 10:57 -0600
      Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-10 13:33 +1000
        Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-10 15:20 +1000
          Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-10 18:59 +1000
      Re: functions, optional parameters Rustom Mody <rustompmody@gmail.com> - 2015-05-09 20:35 -0700
        Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-10 15:25 +1000
      Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-10 12:45 +1000
        Re: functions, optional parameters Dave Angel <davea@davea.name> - 2015-05-10 07:25 -0400
        Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-11 00:39 +1000
        Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-11 07:58 +0200
    Re: functions, optional parameters Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-08 09:48 -0600

csiph-web