【问题标题】:Python: Enum versus Classes [duplicate]Python:枚举与类 [重复]
【发布时间】:2023-04-01 00:50:01
【问题描述】:

我有一个 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 中转换它们应该有什么优势?我还能动态地添加值吗?

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

【问题讨论】:

  • 为什么它们是嵌套类?

标签:
python
python-3.x
class
enums
configuration