[英]access environment variables in Python inside many files
if i need to get the value of an environment variables inside many files in the project Python (flask framework) should i use os.environ['HOME'] for every use or there is better way?如果我需要在项目 Python (烧瓶框架)中的许多文件中获取环境变量的值,我应该在每次使用时使用 os.environ['HOME'] 还是有更好的方法?
for example: auth\routes.py例如:auth\routes.py
username= os.environ.get("USERNAME")
and in routes under posts posts\routes.py并在帖子posts\routes.py下的路线中
username= os.environ.get("USERNAME")
Write a common file to read all your environmental values.编写一个通用文件来读取所有环境值。
config.py配置文件
import os
USERNAME = os.environ.get("USERNAME")
Then you can reuse it like this,然后你可以像这样重用它,
auth\routes.py身份验证\路由.py
import config
username = config.USERNAME
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.