obabs obabs - 10 months ago 66
Python Question

How to check environment variables in python

How to check all environment variables in python. I'm trying to install cx_Oracle and instant client and want to make sure all my variables are ok.


To elaborate further on my comment. All environment variables can be found within the os.environ dictionary (you'll need to import os first).

It looks like TNS_ADMIN is one of the environment variables used for tnsnames.ora, so you can check like this:

import os

if 'TNS_ADMIN' in os.environ:
    print('TNS_ADMIN is set to {}'.format(os.environ['TNS_ADMIN']))
    print('TNS_ADMIN has not been set.')