私信  •  关注

Krishal

Krishal 最近创建的主题
Krishal 最近回复了
6 年前
回复了 Krishal 创建的主题 » 将所有默认值移到一个python文件中

这些枚举应该在配置文件中,或者至少在值中。如果使用这种方式编程,就不会将config.py文件用作配置文件。做下面这样的事情,但要正确编码。

# config.py
from enum import Enum

class WorkerType(Enum):
    A = 'A'
    B = 'B'

class MetricType(Enum):
    EUCLID = 'euclid'
    MANHATTAN = 'manhattan'

DEFAULT_WORKER_TYPE = WorkerType.A
DEFAULT_METRIC_TYPE = MetricType.EUCLID

# worker.py
import config

class Worker: # the same

# metric.py
import config

class Metric: # the same

只从配置导入所需的内容。它打字少,在我心目中更容易阅读。