Python Process Usage Example analysis

Source: Internet
Author: User
This example describes the Python coprocessor usage. Share to everyone for your reference. Specific as follows:

The function is written as a task to handle the series of inputs sent to him, called the co-process

def print_matchs (matchtext):  print "Looking for", Matchtext and  True: line    = (yield)    #用 Yield statement and create a co-path in the form of an expression (yield)    if matchtext in line:      print line>>> matcher = print_matchs (' python ') > >> Matcher.next () Looking for python>>> matcher.send (' Hello python ') #看生成器那片, about the difference between send () and next () Hello Python>>> matcher.send (' test ') >>> matcher.send (' Python is cool ') Python is cool>>> Matcher.close ()

Hopefully this article will help you with Python programming.

  • 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.