utils.py 文件源码

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

项目:lagbot 作者: mikevb1 项目源码 文件源码
def integer(arg):
    """Attempts to return the arg converted to `int`.

    Returns nearest whole number if arg represents a `float`.
    Mainly to be used as typehint in commands.
    """
    try:
        int(arg)
    except ValueError:
        pass
    else:
        return int(arg)

    try:
        float(arg)
    except ValueError:
        pass
    else:
        return int(round(float(arg)))

    raise BadArgument('Converting to "int" failed.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号