Python devops Development (10)----IO multiplexing multithreading, process, and coprocessor

Source: Internet
Author: User

Content directory:

    • Python scope
    • The multiple inheritance differences between python2.7 and python3.5
    • IO multiplexing
    • Multithreading, process, and co-processes
Python scope

No block-level scopes in Python

If 1 = = 1:    name = ' Jabe '    print (name) #可以正常输出jabe # no block-scoped scope in Python # is not used in C # or Java, prompt for name undefined

Function-scoped in Python

def func ():    name = ' Jbae ' func () print (name) #会提示name为定义的报错, indicating that a function is scoped in Python

Python scope chain from inside to look out, until the error is not found

name = ' Jabe ' def F1 ():    # name = ' a '    def f2 ():        # name = ' B '        print (name)    F2 () F1 () #输出jabe

The scope (chain) has been determined before the function is executed

name = ' Jabe ' def F1 ():    print (name) def f2 ():    name = ' LJB '    F1 () f2 () Output: jabe#=============================== name = ' Jabe ' def F1 ():    print (name) def f2 ():    name = ' LJB '    return f1ret = F2 () ret () output: Jabe

Lambda function scope

Li = [lambda:x for x in range]]r = li[0] () print (r) print (' =================== ') #输出为9, the example above is equivalent to the following code Li = []for i in range] (Ten):    def F1 ():        return i    li.append (F1)
#li as a list, the inner element is the function of the same function

Print (Li[0] ()) print (Li[1] ()) print (Li[2] ()) print (Li[3] ()) #输出: # 9# ===================# 9# 9# 9# 9

Since the function is not executed when it is invoked, when the loop ends I is 9 and the last call is 9

The above function can be printed with a slight change of 9.

Li = []for i in range:    def F1 (x=i):        return x    li.append (F1) #li as list, inner element is the same function as function print (Li[0] ()) Print (li[ 1] ()) print (Li[2] ()) print (Li[3] ()) #输出: # 0# # 3

In the above example, the I value is assigned to x because each loop is executed, so the print is 0,1,2,3

The multiple inheritance differences between python2.7 and python3.5

We know from the knowledge we have learned that the multiple inheritance order of the python3.5 class is inherited from left to right and from bottom to top.

In python2.7, if the order for the new class and the py3.5 is the same, the inheritance order of the classic class is slightly different, and the search is deep, until it is found, not to the right.

Do not inherit object is a classic class, inheriting object is a new class (consistent with Py3)

IO multiplexing

Multithreading, process, and co-processes

Python devops Development (10)----IO multiplexing multithreading, process, and coprocessor

Related Article

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.