easyquant/kit/conf.py

40 lines
912 B
Python
Raw Normal View History

2025-07-03 23:39:31 +08:00
class conf:
@staticmethod
def to_int(value: str, params, separator: str = '_'):
return int(value)
@staticmethod
def to_float(value: str, params, separator: str = '_'):
return float(value)
@staticmethod
def to_str(value: str, params, separator: str = '_'):
return str(value)
@staticmethod
def to_bool(value: str, params, separator: str = '_'):
return bool(value)
@staticmethod
2025-07-06 17:42:06 +08:00
def to_list(value: str, separator: str = '_'):
return value.split(separator)
2025-07-03 23:39:31 +08:00
@staticmethod
def config_type(value: str):
data = {
"int": conf.to_int,
"float": conf.to_float,
"str": conf.to_str,
"bool": conf.to_bool,
"list": conf.to_list,
}
return data[value]
2025-07-06 17:42:06 +08:00
ddd = conf.config_type("list")
print(ddd("1_2_3", "_")) # 输出: 123
# "1,2,3".split(",", -1)