constant.py 文件源码

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

项目:nova-fusioncompute 作者: openstack 项目源码 文件源码
def str_to_bool(cver_str):
    """convert string to boolean

    :param cver_str: string should to convert
    :return: Boolean
    """
    if isinstance(cver_str, types.BooleanType):
        return cver_str
    elif isinstance(cver_str, types.StringType):
        bool_map = {'true': True, 'false': False}
        bool_str = cver_str.lower() if cver_str else ""
        if bool_str not in bool_map:
            raise ValueError('%s is not valid boolean.' % cver_str)
        else:
            return bool_map[bool_str]
    else:
        raise ValueError('%s is not valid boolean.' % cver_str)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号