[Tutor] basic decorator question
__peter__ at web.de
Mon Jul 24 12:13:34 EDT 2017
> I've seen sites discuss decorators, as functions that "wrap" and
> return functions.
> But, I'm sooo confuzed! My real question though, can a decorator have
> multiple internal functions? All the examples I've seen so far have a
> single internal function.
> And, if a decorator can have multiple internal functions, how would
> the calling sequence work?
> But as a start, if you have pointers to any really "basic" step by
> step sites/examples I can look at, I'd appreciate it. I suspect I'm
> getting flumoxed by something simple.
Here's a completely useless decorator to drive home the point that
is only a fancy way to write
f = deco(f)
>>> def fortytwo(func):
... print("I don't care about your function")
... return 42
... def f():
... print("this is important")
I don't care about your function
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
More information about the Tutor