def handle_args():
"""Handle the command line arguments provided for the program.
There is an argument for the number of articles to make it configurable.
There is also an argument for the length of the passage to make it configurable.
If the argument is not provided it uses the provided default.
"""
try:
opts, args = getopt.getopt(sys.argv[1:], 'n:l:', ['numberofarticles=', 'passagelength='])
except getopt.GetoptError:
print('wikipedia_quiz.py -n <numberofarticles> -l <passagelength>')
logging.error('Opt error encountered')
sys.exit(2)
number_of_articles = NUMBER_OF_ARTICLES_DEFAULT
passage_length = PASSAGE_LENGTH_DEFAULT
for opt, arg in opts:
if opt in ('-n', '--numberofarticles'):
number_of_articles = int(arg)
logging.info('Number of articles parameter found')
elif opt in ('-l', '--passagelength'):
passage_length = int(arg)
logging.info('Passage length parameter found')
return number_of_articles, passage_length
评论列表
文章目录