Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90187
| 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 | 2015-05-09 03:49 +1000 |
| Subject | Re: functions, optional parameters |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.259.1431107379.12865.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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