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


Groups > comp.lang.python > #16030 > unrolled thread

Re: decorators and closures

Started byAndrea Crotti <andrea.crotti.0@gmail.com>
First post2011-11-21 17:17 +0000
Last post2011-11-21 17:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: decorators and closures Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-21 17:17 +0000

#16030 — Re: decorators and closures

FromAndrea Crotti <andrea.crotti.0@gmail.com>
Date2011-11-21 17:17 +0000
SubjectRe: decorators and closures
Message-ID<mailman.2916.1321895843.27778.python-list@python.org>
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)

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web