bruce wrote:
> Hi.
>
> 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
@deco
def f(...):
...
is only a fancy way to write
def f(...):
...
f = deco(f)
>>> def fortytwo(func):
... print("I don't care about your function")
... return 42
...
>>> @fortytwo
... def f():
... print("this is important")
...
I don't care about your function
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> f
42
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor