Using os
code is generally accepted as bad practice from a security perspective, as it could potentially provide a bad actor with phenomenal cosmic powers. Nonetheless, most sources appear to recommend using the following to get env
variables.
import os
print(os.environ['FOO'])
This approach is also suggested here on SO, such as in "How to access environment variable values?" I know that one can use dotenv to pick up a .env
file and to create new env
variables, but I have not been able to find anything for existing env
variables.
This leads me to the following questions.
- Is Python's
os
secure enough to render my concerns unnecessary? - Is
from os import environ
any better than going for the entireimport os
? - Is there a method that is more secure and avoids
os
entirely?
Thanks muchley!