click_utils.py 文件源码

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

项目:TigerHost 作者: naphatkrit 项目源码 文件源码
def prompt_choices(choices):
    """Displays a prompt for the given choices

    :param list choices: the choices for the user to choose from

    :rtype: int
    :returns: the index of the chosen choice
    """
    assert len(choices) > 1
    for i in range(len(choices)):
        click.echo('{number}) {choice}'.format(
            number=i + 1,
            choice=choices[i]
        ))
    value = click.prompt('1-{}'.format(len(choices)), type=int) - 1
    if value < 0 or value >= len(choices):
        raise click.ClickException('Invalid choice.')
    return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号