Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16081
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2011-11-22 09:03 -0800 |
| References | <mailman.2903.1321886678.27778.python-list@python.org> |
| Subject | Re: decorators and closures |
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| Message-ID | <mailman.2951.1321981431.27778.python-list@python.org> (permalink) |
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
>
> def nested():
> @dec
> def fun():
> print("here")
>
> nested()
> nested()
>
> Will give:
> In decorator
> In decorator
>
> So we were wondering, would the interpreter be able to optimize this
> somehow?
> I was betting it's not possible, but I'm I would like to be wrong :)
I love to use decorators. I did the same things to functions and structures in c long time ago. I think that might be the dark night era in programming in the early 90's long long ago.
Cheers.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
decorators and closures Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-21 14:44 +0000 Re: decorators and closures Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-22 03:54 +0000 Re: decorators and closures 88888 Dihedral <dihedral88888@googlemail.com> - 2011-11-22 09:03 -0800 Re: decorators and closures 88888 Dihedral <dihedral88888@googlemail.com> - 2011-11-22 09:03 -0800
csiph-web