Python
Access environment variable in Python
Access environment variable in Python
envenvironment
Interactive recipe
You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.
Python code
# Python code will be here
Code explanation
- Get environment variable.
- If variable is not empty it is displayed.
Additionally, you can set default value when get value from environ dictionary. For example:
my_var = os.envrion.get("MY_ENV_VARIABLE", "some_default_value")
To list all environment variables, please use:
print(os.environ)
Python cookbook
Code recipes from Python cookbook.
- Previous
- Get working directory