What I would like to do is when I enter a specific argument it starts a function, is this possible through argparse
. So if I hit the add argument in my application it triggers the "add" function.
parser = argparse.ArgumentParser(description='to do list')
parser.add_argument('-a', '--add', help='add an item to the todo list')
parser.add_argument('-r', '--remove',)
parser.add_argument('-l', '--list',)
args = parser.parse_args()
def add(args):
conn = sqlite3.connect('todo.db')
c = conn.cursor()
c.execute("INSERT INTO todo VALUES (args.add, timestamp)")