coroutine in the python

technical talkiess
0

 Coroutine in python:- 

import time

def searcher():

    # yaha par kuch time lagne wala hai code ko to

    time.sleep(2)

    book = "Vishal is the honest boy here"

    while True:

        text = (yield)

        if text in book:

            print("Availble here")

        else:

            print("Not available here")



# yaha par coroutine chalu kiya hai hamne

search = searcher()

next(search)

# yaha par kuch value send karni hai

search.send("Vishal")


# yaha par usko close kiya hai

search.close()




Coroutine exe :- 

import time

# f = open('fs')

def searcher():

    # yaha par kuch time lagne wala hai code ko to

    time.sleep(4)

    book = open('test.txt','r')

    book = book.readlines()

    while True:

        text = (yield)

        for text in book:

            if text in book:

                print("Availble here")

            else:

                print("Not available here")



# yaha par coroutine chalu kiya hai hamne

search = searcher()

next(search)

# yaha par kuch value send karni hai

print("Enter the name which is you want to search ....")

name = input()

search.send(name)


# yaha par usko close kiya hai

search.close()
Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)