The reason you are encountering this error is that, you need to provide train
arguments to parse_args() method either like following or providing it in command line:
import argparse
def get_options():
parser = argparse.ArgumentParser(description='Parses Command.')
parser.add_argument('-t', '--train', nargs='+', help='Training data directories.')
parser.add_argument('-i', '--iteration', type=int, nargs='+', help='Number of iteration.')
options = parser.parse_args(['-t', 'train1', 'train2'])
return options
options = get_options()
print('train arguments:', options.train)
for option in options.train:
print('train:', option)
Result of above code is the following:
train arguments: ['train1', 'train2']
train: train1
train: train2
Assuming the above Python code is saved into a file called train.py, it can be run at the command line without specifying arguments to parse_args() method:
$ python train.py -t train/etc train/etc2
train arguments: ['train/etc', 'train/etc2']
train: train/etc
train: train/etc2
In case there is no -t args to parse there is a possible way to handle occurred exception in try-except code block or refer to Python argparse: Make at least one argument required for more solutions of ensuring availability of inputs.