python read environment variables from file - How to access environment variable values?

python environment variables windows 10 / python / environment-variables

I set an environment variable that I want to access in my Python application. How do I get its value?


Answer #1

Actually it can be done this away:

import os

for item, value in os.environ.items():
    print('{}: {}'.format(item, value))

Or simply:

for i, j in os.environ.items():
    print(i, j)

For view the value in the parameter:


To set the value:

os.environ['HOME'] = '/new/value'