我在Python中有一个配置文件。建议我使用类。所以我有很多这样的常量:
class Paths:
class Sources:
strategylab = 'src/strategylab/'
class Projects:
home = 'prj/'
os.makedirs(home, exist_ok=True)
scenarios_outputs = 'outputs/'
scenarios = 'scenarios/'
datasets = 'datasets/'
# to be configured dinamically
project_path = None
project_single_scenario_path = None
project_single_scenario_output_path = None
project_outputs_path = None
project_name = None
project_datasets_path = None
class Workspace:
temp = 'temp/'
ftp = 'ftp/'
# to be configured dinamically
home = None
temp_location = None
ftp_location = None
class Template:
home = 'model/'
# to be configured dinamically
single_project_template_location = None
如果在ENUM中进行转换,我应该具有哪些优势?我还可以动态地添加值吗?
编辑:相关问题并没有解决我的疑问,因为我不是在寻找一般用例,而是在寻找使用简单类的优势。
答案 0 :(得分:1)
SeniorCitizen
用于常量-硬盘驱动器上的路径感觉不是很恒定:
枚举不能在创建后添加值。