get_file_type get_function(module"get_file_type"if get_file_type is not noneget_file_type_functions append(get_file_typein momentwe will look at three different implementations of the load_modules(function which returns (possibly emptylist of module objectsand we will look at the get_function(function further on for each module found we try to retrieve get_file_type(functionand add any we get to list of such functions for file in get_files(sys argv[ :])fh none tryfh open(file"rb"magic fh read( for get_file_type in get_file_type_functionsfiletype get_file_type(magicos path splitext(file)[ ]if filetype is not noneprint("{ < }{ }format(filetypefile)break elseprint("{ < }{ }format("unknown"file)except environmenterror as errprint(errfinallyif fh is not nonefh close(this loop iterates over every file listed on the command line and for each one reads its first bytes it then tries each get_file_type(function in turn to see whether it can determine the current file' type if the file type is determinedthe details are printed and the inner loop is broken out ofwith processing continuing with the next file if no function can determine the file type--or if no get_file_type(functions were found--an "unknownline is printed we will now review three different (but equivalentways of dynamically importing modulesstarting with the longest and most difficult approachsince it shows every step explicitlydef load_modules()modules [for name in os listdir(os path dirname(__file__or ")if name endswith(py"and "magicin name lower()filename name name os path splitext(name)[ if name isidentifier(and name not in sys modules