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)
评论列表
文章目录