Access environment variables from Python -
i set environment variable want access in python application. how value?
environment variables accessed through os.environ
import os print os.environ['home']
or can see list of environment variables using:
os.environ
as might need see complete list!
# using return `none` if key not present rather raise `keyerror` print os.environ.get('key_that_might_exist') # os.getenv equivalent, , can give default value instead of `none` print os.getenv('key_that_might_exist', default_value)
python default installation on windows c:\python
. if want find out while running python can do:
import sys print sys.prefix
Comments
Post a Comment