Where are the environmental variables in Python?

Asked 2 years ago, Updated 2 years ago, 103 views

There are two things I would like to ask.

python env environment-variables

2022-09-22 22:34

1 Answers

Environmental variables can be found in os.environ.

import os
print os.environ['HOME']

# If there is no key, return None, not KeyError
print os.environ.get('KEY_THAT_MIGHT_EXIST')

# Features such as get. Instead, you can specify default_value instead
print os.getenv('KEY_THAT_MIGHT_EXIST', default_value)


2022-09-22 22:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.