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 def to_list(value: str, separator: str = '_'): return value.split(separator) @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] ddd = conf.config_type("list") print(ddd("1_2_3", "_")) # 输出: 123 # "1,2,3".split(",", -1)