Timothy Goh
Timothy Goh

Reputation: 55

passing param to asyncio.run() function via command line

I'm kinda new to Python I would like to ask how can I pass a param to the async function via commandline

async def main(action):
    async with TelegramClient('session', api_id, api_hash) as client:
        time = get_time()
        if action == 'in':
            message = "It's " + time + ". Time to work."
        else:
            message = "It's " + time + ". Let's call it a day."

        await client.send_message('me', message)
asyncio.run(main(WHAT_SHOULD_I_USE_HERE_OTHER_THAN_input()))

Upvotes: 0

Views: 2722

Answers (1)

user122644
user122644

Reputation: 109

argparse is the way to go https://docs.python.org/3/library/argparse.html

minimum example:

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--argument', metavar='N', type=str)
args = parser.parse_args()

and then use python script.py --argument my_argument. args.argument will be the string 'my_argument'.

Upvotes: 2

Related Questions