Python decorators

· randomwork's blog

Read an article about "Python decorators".

I'm sure I anwser that in interviews. It's just a syntax for a function call. You use a decorator to decorate a function. That decotartor is a function call. A function call to return a new function from the decorated function. In the decorator function, you must return a function, return a function that usually change somthing from the decorated function. The decorated function is a parameter to the decorator function, so you can just return it unchanged. But that mean the decorator doing nothing, so you better return another function. The another function usually called the decorated function with something changed. That's how decorators works.

Well only part of, I don't know how it's implemented, as python sources are hard to read. Maybe not hard, just I haven't read them. I'm lazy...