Mar-10-2017, 03:08 PM
#! /usr/bin/python3 import os import sys def get_environment_variable_value(variable_name): return os.environ.get(variable_name,'') def get_dirs_from_path(): path_var = get_environment_variable_value('PATH') directories = path_var.split(':') for entry in directories: print (entry) get_dirs_from_path()Note the way I change the get_environment_variable_value(variable_name). In your code there you will get KeyError if variable_name is not in the list of environment variables. This more or less removes the need of additional function...