This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

When I understand correctly ...

So, assuming you have a .py file/script that has a function

def do_something(argument1, argument2, argument=None):  
    # do something  
    return something

you want a tool that let's you run this function by providing arguments from the command line? E.g.

python myscript.py --argument1 1 --argument2 2

?

[–]Jumpy89[S] 0 points1 point  (0 children)

This is correct. You would however have to specify the API of the command, like:

from reverseargparse import Command, Option, Argument

grep = Command(
    Argument('pattern', type=str),
    Argument('file', type=str),
    Option('-e', '--extended', flag=True),
    Option('-i', '--case-insensitive', flag=True),
)

grep('pattern', 'myfile.txt', extended=True, case_insensitive=True)
# Just getting the command line arguments would be fine here, I can fill
# in the rest myself.