Home  >  Article  >  Backend Development  >  How to get environment variables in Python

How to get environment variables in Python

silencement
silencementOriginal
2019-05-23 17:28:556087browse

How to get environment variables in Python

Method 1 os reading

os reads directly and uses os to obtain the environment variable dictionary

How to get environment variables in Python

Print All environment variables, traverse the dictionary

How to get environment variables in Python

Method 2 pyhocon reading

pyhocon is a python configuration management library

pyhocon One of its functions is that it can be directly referenced using ${} in the configuration file. When pyhocon parses, it will automatically implement the above resolveEnv logic, corresponding to the environment variable.

The official website is as follows:https://github.com/chimpler/pyhocon

The configuration file is as follows:

default.conf

How to get environment variables in Python

${HOME} will automatically obtain the HOME in the environment variable when parsing and using parsing

How to use

How to get environment variables in Python

The above is the detailed content of How to get environment variables in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn