On Monday, November 21, 2011 10:44:34 PM UTC+8, Andrea Crotti wrote:
> With one colleague I discovered that the decorator code is always
> executed, every time I call
> a nested function:
>
> def dec(fn):
> print("In decorator")
> def _dec():
> fn()
>
> return _dec
>
> d
On Mon, 21 Nov 2011 14:44:34 +, Andrea Crotti wrote:
> With one colleague I discovered that the decorator code is always
> executed, every time I call a nested function:
"def" is a statement which is executed at runtime. Often people will talk
about "definition time" instead of "compile time
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
functi
On 11/21/2011 10:35 AM, Andrea Crotti wrote:
On 11/21/2011 03:06 PM, Dave Angel wrote:
Your function 'nested' isn't nested, 'fun' is. What you discovered is
that a decorator is always executed, every time a nested decorated
function is defined.
You've also ust proved that it would be an incompa
On 11/21/2011 03:06 PM, Dave Angel wrote:
Your function 'nested' isn't nested, 'fun' is. What you discovered is
that a decorator is always executed, every time a nested decorated
function is defined.
You've also ust proved that it would be an incompatible change.
Doesn't that answer the que
On 11/21/2011 09:44 AM, Andrea Crotti wrote:
With one colleague I discovered that the decorator code is always
executed, every time I call
a nested function:
def dec(fn):
print("In decorator")
def _dec():
fn()
return _dec
def nested():
@dec
def fun():
print
With one colleague I discovered that the decorator code is always
executed, every time I call
a nested function:
def dec(fn):
print("In decorator")
def _dec():
fn()
return _dec
def nested():
@dec
def fun():
print("here")
nested()
nested()
Will give:
In dec