Posts Tagged ‘env’

Reading environment variables in python

Posted: 13th November 2012 by Tim in Python
Tags: , , , , , ,

Shell envronment variables contain many useful paths and settings. At times you may want to use these variables from within a python program. This can be done via the os.path.expandvars(<var>) call, defined in os.path. For example, the following program: import os.path print os.path.expandvars(‘$SHELL’); Will print (on my machine): /bin/bash