access environment variables in Python inside many files
Question:
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?
for example:
authroutes.py
username= os.environ.get("USERNAME")
and in routes under posts
postsroutes.py
username= os.environ.get("USERNAME")
Answers:
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,
authroutes.py
import config
username = config.USERNAME
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?
for example:
authroutes.py
username= os.environ.get("USERNAME")
and in routes under posts
postsroutes.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,
authroutes.py
import config
username = config.USERNAME