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: 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> <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 Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sat, May 9, 2015 at 3:36 AM, Steven D'Aprano 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