How to get an environment variable in Python?

In Python, how to get an environment variable?

asked Mar 17 by anonymous

1 Answer

In Python, you may use this piece of code to get an environment variable:

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.

Reference and for more ways, please check https://www.systutorials.com/dtivl/13/how-to-get-an-environment-variable?show=80#answer-80 .

answered Apr 20 by zma (380 points)
edited Apr 20 by zma

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...