why does positional arguments not work if python path is not given to execute python file

  argparse, python, windows
parser = argparse.ArgumentParser()
parser.add_argument("-f","--first", action="store_true", default=False, help = "Execute first option")
parser.add_argument("-s","--second", action="store_true",default=False, help = "Execute second option")
parser.add_argument("-t","--third", action="store_true", default=False, help = "Execute third option")
args = parser.parse_args()

if args.first:
    print("i am the 1st option")

elif args.second:
    print("i am the 2nd option")

elif args.third:
    print("i am the last option")

I am trying to open command line and execute below code with "python sample.py" – first. It works, but I try to execute only "Sample.py -first" it doesnt take any arguments. Please help

Source: Windows Questions

LEAVE A COMMENT