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")
Asked By: avtar550

||

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
Answered By: Rahul K P
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.