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


Groups > comp.lang.python > #90187

Re: functions, optional parameters

X-FeedAbuse http://nntpfeed.proxad.net/abuse.pl feeded by 195.154.70.45
Path csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'argument': 0.05; '"""': 0.07; "'',": 0.07; 'context': 0.07; 'attributes': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; '"""\\': 0.16; '"code': 0.16; 'closures': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'func():': 0.16; "function's": 0.16; 'read-only.': 0.16; 'subject:parameters': 0.16; 'time"': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'print': 0.22; 'compilation': 0.24; 'lets': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'pass': 0.26; 'code:': 0.26; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'created': 0.35; 'definition': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'object,': 0.36; 'two': 0.37; 'being': 0.38; 'rather': 0.38; 'anything': 0.39; 'aside': 0.39; 'sure': 0.39; 'how': 0.40; 'is.': 0.60; 'skip:* 10': 0.61; 'show': 0.63; 'different': 0.65; 'between': 0.67; 'default': 0.69; '2015': 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=7SXjNLAVTsEpBJFseYX7DQWqcyCqaMlLTDWzzu9fSTE=; b=MrTVXQnLXTaLnYnHAjJ11yFDdM/tB+oV7imVRw5lmlbBTd+AzcX6sKupb56n0Z10C6 61LiFjIe5Qox6aSmIbXz9/wM/fhK6hCDQCmHBNVuH/jepkiRBINylfZcX3op2hRUfaXK iArxAhBSuosCz2FgjgrL3dwbWaRWHMH0FYryu5SeB5LuZ1o38MNiv6C9T3pM2MSMb3CE MB47Dx15jNrjURs9ukeI5f8rT5jfV/W5DIZnYl40zcArdp/2Xkgmv7++K/VPYQzkL/pq 3Gyv7FFiso3EXVanAn6jb+IYcwtrU4S3rB4jhMJ2mUt3w6E9yZu2+n2miBmz6SbnWE+w y1cg==
MIME-Version 1.0
X-Received by 10.107.134.206 with SMTP id q75mr6474236ioi.27.1431107376393; Fri, 08 May 2015 10:49:36 -0700 (PDT)
In-Reply-To <554cf421$0$12978$c3e8da3$5496439d@news.astraweb.com>
References <72lu1cxvmg.ln2@news.c0t0d0s0.de> <554cd511$0$12979$c3e8da3$5496439d@news.astraweb.com> <CALwzidnkFF3DZws_5q=O6g9DFyFD5yK=BvHY2DtRoCVnZYLdyw@mail.gmail.com> <mailman.256.1431100965.12865.python-list@python.org> <554cf421$0$12978$c3e8da3$5496439d@news.astraweb.com>
Date Sat, 9 May 2015 03:49:36 +1000
Subject Re: functions, optional parameters
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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.259.1431107379.12865.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431107379 news.xs4all.nl 2830 [2001:888:2000:d::a6]:51172
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90187

Show key headers only | View raw


On Sat, May 9, 2015 at 3:36 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Sat, 9 May 2015 02:02 am, Chris Angelico wrote:
>> 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.
>
> Sure there is. Write this Python code:
>
> py> source = """\
> ... print "Function definition time."
> ... def func():
> ...     pass
> ... """
> py> print "Compile time."; code = compile(source, '', 'exec')
> Compile time.
> py> exec(code)
> Function definition time.

Yes, but can you *distinguish* them in terms of default argument
versus code object creation? How do you know that the function's code
object was created when compile() happened, rather than being created
when the function was defined? Is there anything that lets you in any
way show different behaviour based on that timing difference?

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