Once you understand it is just a big dictionary it is simple to have a world of environmental information available for wherever your program may be run. In order to access them one at a time though, we need to get the keys in a list, which we can do with the list() command applied to our captured dictionary. It is helpful to get rid of the PATH information which really messes up trying to look at the data and use Pretty Print as a nice display. Of course maybe you want to see that path information. Here are a few lines of code that give you both:
import os import pprint pp = pprint.PrettyPrinter() adic = dict(os.environ) keylist = list(adic.keys()) for item in keylist: print(item, end=" = ") if item == "PATH": print("skipping PATH output") continue else: print(adic[item]) print("\n"*2,"-----PATH INFORMATION-----","\n"*2) pp.pprint(os.environ['PATH'])
Here is a list of what you will find and have available with: print(os.environ[‘item_name’])
‘ALLUSERSPROFILE’,
‘APPDATA’,
‘ASL.LOG’,
‘COMMONPROGRAMFILES’,
‘COMMONPROGRAMFILES(X86)’,
‘COMMONPROGRAMW6432’,
‘COMPUTERNAME’,
‘COMSPEC’,
‘CONFIGSETROOT’,
‘CYGWIN’,
‘DRIVERDATA’,
‘FPS_BROWSER_APP_PROFILE_STRING’,
‘FPS_BROWSER_USER_PROFILE_STRING’,
‘HOME’,
‘HOMEDRIVE’,
‘HOMEPATH’,
‘LOCALAPPDATA’,
‘LOGONSERVER’,
‘MOZ_PLUGIN_PATH’,
‘NUMBER_OF_PROCESSORS’,
‘ONEDRIVE’,
‘ONEDRIVECONSUMER’,
‘OS’,
‘PATH’,
‘PATHEXT’,
‘PIP37’,
‘PROCESSOR_ARCHITECTURE’,
‘PROCESSOR_IDENTIFIER’,
‘PROCESSOR_LEVEL’,
‘PROCESSOR_REVISION’,
‘PROGRAMDATA’,
‘PROGRAMFILES’,
‘PROGRAMFILES(X86)’,
‘PROGRAMW6432’,
‘PSMODULEPATH’,
‘PUBLIC’,
‘PYTHON’,
‘PYTHON37_HOME’,
‘PYTHON37_SCRIPTS’,
‘SYSTEMDRIVE’,
‘SYSTEMROOT’,
‘TEMP’,
‘TMP’,
‘USERDOMAIN’,
‘USERDOMAIN_ROAMINGPROFILE’,
‘USERNAME’,
‘USERPROFILE’,
‘VBOX_MSI_INSTALL_PATH’,
‘WINDIR’