def convert2type(value, data_type='str'):
"""Convert value to data_type and return value in that data_type
Currently supported are str/int/float only
"""
type_funcs = {'str': str, 'int': int, 'float': float}
convert = type_funcs[data_type]
cvalue = value
try:
cvalue = convert(value)
except ValueError:
print_error("'{}' should be of type {}, please correct".format(value, data_type))
except Exception as exception:
print_exception(exception)
return cvalue
评论列表
文章目录