python 获取环境变量
In Python, how to get an environment variable?
在Python中 ,如何获取环境变量?
In Python, you may use this piece of code to get an environment variable:
在Python中,您可以使用以下代码来获取环境变量:
os.environ.get('ENV_MIGHT_EXIST')
or this piece of code:
或这段代码:
os.getenv('ENV_MIGHT_EXIST')
It will return None
if the environment variable is not present.
如果环境变量不存在,它将返回None
。
Reference and for more ways, please check https://www.systutorials.com/dtivl/13/how-to-get-an-environment-variable?show=80#answer-80 .
参考以及更多方法,请检查https://www.systutorials.com/dtivl/13/how-to-get-an-environment-variable?show=80#answer-80 。
Answered by zma.
由zma回答。
翻译自: https://www.systutorials.com/how-to-get-an-environment-variable-in-python/
python 获取环境变量