Back
I set an environment variable that I want to access in my Python application. How do I get this value?
import os print(os.environ['HOME'])
import os
print(os.environ['HOME'])
import sys print(sys.prefix)
import sys
print(sys.prefix)
try: os.environ["FOO"] Except KeyError: print ("Please set the environment variable FOO") sys.exit(1)
try:
os.environ["FOO"]
Except KeyError:
print ("Please set the environment variable FOO")
sys.exit(1)
To know more about this you can have a look at the following video tutorial:-
31k questions
32.8k answers
501 comments
693 users