0 votes
1 view
in Python by (47.8k points)

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

1 Answer

0 votes
by (107k points)
edited by
  • We can access the list of environment variables through os.environ.

   import os



  • Following is the piece of code only for Windows to find the environment variable:- 

import sys 


  • You can use the following code to check the environment variable in Python on all the Os:-



Except KeyError:

   print ("Please set the environment variable FOO")


To know more about this you can have a look at the following video tutorial:-

Welcome to Intellipaat Community. Get your technical queries answered by top developers !