0

I am attempting to create a script that will continuously run the code with asyncio if its possible..

# parse_name.py

import parse
import asyncio


async def parse_name(text: str) -> str:
    patterns = (
        "my name is {name}",
        "i'm {name}",
        "i am {name}",
        "call me {name}",
        "{name}",
    )
    for pattern in patterns:
        result = parse.parse(pattern, text)
        if result:
            return result["name"]
    return ""

answer = input("What is your name? ")
name = parse_name(answer)
print(f"Hi {name}, nice to meet you!")


async def main():
    divs1 = loop.parse_name(text)
    await asyncio.wait([divs1])
    return divs1


if __name__ == "__main__":
    try:
        loop = asyncio.get_event_loop()
        loop.set_debug(1)
        d1 = loop.run_until_complete(main())
    except Exception as e:
        # logging...etc
        pass
    finally:
        loop.close()

Basically this script will open up a command prompt... But then close out immediately.. The name prompt comes up, what I inserted doesnt come thru blah blah and it also closes out. Would anyone be able to give me a tip where this script would run continuously? Basically after the nice to meet you!" it would loop back to "What is your name? "

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
=========== RESTART: C:/Users/benb/Desktop/text_parse/loopTest.py ===========
What is your name? blah blah
Hi <coroutine object parse_name at 0x000001A8F0526BF8>, nice to meet you!
>>> 
bbartling
  • 3,288
  • 9
  • 43
  • 88
  • If you just want to write some code continuously just put this code inside `while True:`. `asyncio` should be used for specific tasks, there's usually no need in `asyncio` for non-IO functions. Read [this answer](https://stackoverflow.com/a/33399896/1113207) it may be helpful. – Mikhail Gerasimov Sep 24 '19 at 16:30
  • @MikhailGerasimov that actually worked for everything I wanted to do with the `while True` loop if you post an answer I can hit the green check. Thanks – bbartling Sep 24 '19 at 17:10

0 Answers0