Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16030
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andrea.crotti.0@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.043 |
| X-Spam-Evidence | '*H*': 0.91; '*S*': 0.00; 'python': 0.08; 'def': 0.13; '3.2,': 0.16; 'closure.': 0.16; 'object)': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; 'switched': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'code': 0.25; 'function': 0.27; 'import': 0.27; 'variable': 0.28; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'definition': 0.30; 'object.': 0.30; 'source': 0.31; "didn't": 0.31; 'version': 0.32; 'message-id:@gmail.com': 0.33; 'header:User-Agent:1': 0.33; 'actually': 0.33; 'anything': 0.34; 'received:74.125.82': 0.35; 'running': 0.35; 'opposed': 0.37; 'but': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'using': 0.38; 'received:10.0.0': 0.38; 'some': 0.38; 'supply': 0.69; 'have.': 0.77; '05:11': 0.84; 'yours.': 0.95 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=XB8bQztoM97bdb5eDgzOFF3Nr/nARcZOrIDuGtAE9YY=; b=gwhQxC5Qo0fFM70Od7teUQFPy24EgVSnZtXST3rglqsLHyoG3Zyq1EusSl72SxWfJQ qyyDXBX4/95x+VUj8n7zWdWxRjpE/XV5eFovq7DttHdVTkKcJo4Js0PuVoP1gx+0YrNF 3+A3mkxCE91mCQSKEcujwFzOR6JJvHWVZKtjE= |
| Date | Mon, 21 Nov 2011 17:17:12 +0000 |
| From | Andrea Crotti <andrea.crotti.0@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111108 Thunderbird/8.0 |
| MIME-Version | 1.0 |
| To | d@davea.name |
| Subject | Re: decorators and closures |
| References | <4ECA63D2.7080603@gmail.com> <4ECA68D8.2060608@davea.name> <4ECA6FB1.6000701@gmail.com> <4ECA8642.7060908@davea.name> |
| In-Reply-To | <4ECA8642.7060908@davea.name> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2916.1321895843.27778.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1321895843 news.xs4all.nl 6915 [2001:888:2000:d::a6]:56974 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16030 |
Show key headers only | View raw
On 11/21/2011 05:11 PM, Dave Angel wrote:
>
> You didn't mention what version of Python you're running. With Python
> 2, I got very different results. So I switched to Python 3.2, and I
> still don't get exactly what you have.
>
> A closure is needed if there's some non-global data outside the
> function definition (code object) that's needed by the function
> object. As you supply the code I don't need a closure. But if I add
> a local variable in test_decorate(), and refer to it in dec(), then I
> get one. Not the same as yours.
>
> You left out the import and the definition line for test_decorate.
> Did you leave anything else? And what version of Python are you
> using? Are you perhaps running in a shell, as opposed to running code
> directly from a source file?
I use python 2.7, and actually the whole source is this (test_decorate.py):
def dec(fn):
def _dec():
fn()
return _dec
@dec
def fun():
print("here")
fun()
Using ipython:
import test_decorate
dis.dis(test_decorate)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: decorators and closures Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-21 17:17 +0000
csiph-web