[SOLVED] How to list out all the environment variable in python?

Issue

This Content is from Stack Overflow. Question asked by Hasidul Islam

I want to list out all the environment variables in my system in python. The list should give me the name of the variable and its value.



Solution

Using os module of python it is possible to list out the environment variables.

import os

for name, value in os.environ.items():
    print("{0}: {1}".format(name, value))


This Question was asked in StackOverflow by Hasidul Islam and Answered by Hasidul Islam It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?