Tag Archives: Python problem handling

[Solved] error: the following arguments are required (Default parameters are set)

When using the arguparse parameter list, if a parameter specifies a default value, it still displays: error: the following arguments are required

Solution:

1. Replace required=True with required=False.

2. Add — before parameter name.

As follows:

parser.add_argument('--mode', '-M', dest='mode', action='store', required=True,
                    choices=['train', 'test'], default='train',
                    help='Mode in which the script is executed.')