Python: argparse optional arguments without dashes

前端 未结 3 1086
终归单人心
终归单人心 2021-01-01 12:58

I would like to have the following syntax:

python utility.py file1 FILE1 file2 FILE2

where file1 and file2 are optional arguments. It is si

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 13:42

    Another Example would be:

    train.py
    
    import argparse
    if __name__ == '__main__':
        parser = argparse.ArgumentParser(description="Arguments for wake_word")
        parser.add_argument('data', type=str, help="path to data")
        parser.add_argument('output', type=str, help="model save path")
        parser.add_argument('batch_size', type=int, help="batch size")
        parser.add_argument('epochs', type=int, help="no.s of epochs")
        args = parser.parse_args()
    print(args.data + args.output + args.batch_size + args.epochs)
    

    then you can just run this code with arguments without dash

    train.py /path/to/data/ /path/to/output_files/ 128 100
    

    And, in ascending order

提交回复
热议问题