Method 1 os reading
os reads directly and uses os to obtain the environment variable dictionary
Print All environment variables, traverse the dictionary
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
${HOME} will automatically obtain the HOME in the environment variable when parsing and using parsing
How to use
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!