Python Basics 12 Adorner advanced

Source: Internet
Author: User

The main contents of this section :
1. review of the pass decorator
2. information about the function
3. decorative Adorner with parameters
4. a plurality of adorners are decorated at the same time. Functions

? . review of the pass-through decorator
Opening and closing principle : open to increase function . enclosing the modified code
Decorator's work? : adds functionality to functions without changing the original code
The way the decorator is written :

Execution process:

In fact, executing target_func () is the execution of the inner function. The inner function executes the code before the target function, executes the target function, and then executes the code after the target function.

How to get useful information about a function:

Function name. __name__ can see the name of the functions

Function name. __doc__ can view functions document comments

Although the call is the Target_func function, but printed out is the inner function, this will inevitably give me misunderstanding, so we have to change back

PS: When *args and **kwargs break up, when to converge
1. when the parameter is received, it is aggregated , parameter declaration
2. passing parameters is scattered , passing arguments to the function

Three--Decorator

Execution order: executes Wrapper_out first (False), the return value is wrapper, and then @wrapper or the same as the previous adorner, one execution at a time.

four . multiple adorners decorated with a function
Read first, then the code .

This order can be smoothed by itself. Perform adorner 1 and then perform adorner 2

Python Basics 12 Adorner advanced

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.