Python Road-Decorators

Source: Internet
Author: User

I. Adorner pre-placement knowledge essentials

1. Namespaces

places where names and variables are bound

Classification of namespaces:

Built-in namespaces: where the Python interpreter starts, storing its own name. (such as built-in functions)

Global namespaces: Where file-level names are stored when the file is executed

Local namespaces: During the execution of a file, if the function is called, where the function is used to hold the default name, the call takes effect, and the call ends after it expires.

Load order: Built-in--------"Global----------" local

Lookup Order: Local--------"Global----------" built-in

2. Scope

Scope: Range of effects

(1). Global scope (Globals ())

Global survival, globally valid

(2). Local scope (locals ())

Temporary survival, partially effective

Note: 1. Scope relationship, function definition has been determined, and function call location independent, in the call function is back to the original definition function

Position to find the scope relationship.

3. Closure function

Definition: A function defined inside that contains a reference to an outer scope, not a reference to a global scope, which is a closure function

Two. Decorative Device

Adorner Purpose: to follow the principle of the premise of adding new functions for other functions

the adorner follows the principle: 1. Do not modify the source code of the adorned object 2. Do not modify the calling method of the called Object

Examples of non-parametric adorners:

Example of a parameter function:

Python Road-Decorators

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.