Coroutines In Python | Python Tutorials For Absolute Beginners In Hindi #77

Code as described/written in the video


def searcher():
    import time
    # Some 4 seconds time consuming task
    book = "This is a book on harry and code with harry and good"
    time.sleep(4)

    while True:
        text = (yield)
        if text in book:
            print("Your text is in the book")
        else:
            print("Text is not in the book")

search = searcher()
print("search started")
next(search)
print("Next method run")
search.send("harry")

search.close()
search.send("harry")
# input("press any key")
# search.send("harry and")
# input("press any key")
# search.send("thi si")
# input("press any key")
# search.send("joker")
# input("press any key")
# search.send("like this video")



Comments(2)

Prafullep at 2019-06-23 09:30:09 says
Sorry nahi samajh me aaya
Ansh_Shrivas at 2019-06-23 09:30:09 says
My function in not working def file(): with open('Docs.txt','a+') as f: inp=input('Enter text in file : ') f.write(f'{inp}') def searcher(): with open('Docs.txt') as f: while True: text = (yield) if text in f: print("Your text is in the book") else: print("Text is not in the book") file() search = searcher() print("search started") next(search) print("Next method run") search.send("in this") search.close() # input("press any key") # search.send("harry and") # input("press any key") # search.send("thi si") # input("press any key") # search.send("joker") # input("press any key") # search.send("like this video")