wikipedia_quiz.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:WikipediaQuiz 作者: NicholasMoser 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号