python文件无法配置.env文件中的变量

时间:2019-06-26 10:15:10

标签: python-3.x

我有一个.py文件,并且在其中,我有一些我不希望其他人看到的常量,因此,我包含了.env文件。但是,在运行文件时,我收到一条错误消息,提示找不到该变量

from decouple import config

#CONSTANTS START
inflation_rate = int(config('inflation_rate'))
pv = int(config('pv'))
#CONSTANTS END

.env file:
inflation_rate=0.05
pv=0

错误消息:

File "final_deep.py", line 21, in <module>
    inflation_rate = int(config('inflation_rate'), default=0.05)
  File "/Users/AC/Desktop/virtualenvs/basis_funds/lib/python3.7/site-packages/decouple.py", line 197, in __call__
    return self.config(*args, **kwargs)
  File "/Users/AC/Desktop/virtualenvs/basis_funds/lib/python3.7/site-packages/decouple.py", line 85, in __call__
    return self.get(*args, **kwargs)
  File "/Users/AC/Desktop/virtualenvs/basis_funds/lib/python3.7/site-packages/decouple.py", line 70, in get
    raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: inflation_rate not found. Declare it as envvar or define a default value.

0 个答案:

没有答案