How to get an environment variable in Python
In this article, we will show you how to access the environment variables in Python. import os print(os.environ[‘HOME’]) print(os.getenv(‘HOME’)) P.S Tested with Python 3.9.5 1. Get an environment variable 1.1 The below code uses [os.environ(https://docs.python.org/3/library/os.html#os.environ) to print the environment variable HOME. import os print(os.environ[‘HOME’]) # /Users/mkyong 1.2 If the requested key does not exist, it …