从外部文件导入常量到 python

Import constant from external file into python

我想从外部文件导入常量。我在一个目录中有两个文件。 constants.py 文件:

SOME_CONSTANT = 'something'

并将其导入 settings.py

import constants

someVariable = constants.SOME_CONSTANT

但是 pylint 写 Module 'constants' has no 'SOME_CONSTANT' member

无法真正说明您是如何创建常量的,但理想情况下您希望将它们存储在您的 class 中。

#Constants.Py
class Province:
    CITY = 'Toronto'

#Settings.Py
from Constants import Province
someVariable = Province.CITY
>>> 'Toronto'