Python:枚举与类

2024-10-01 13:36:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个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中转换它们,我应该有什么优势?我还能以平日的方式增加价值吗

编辑:相关的问题没有回答我的疑问,因为我搜索的不是一般用例,而是相对于使用简单类的优势


Tags: topathprojectnonehomeftpbeoutputs