(filename)
Call the relevant function from extensions_to_functions_dict, based on the filename.
Call the relevant function from extensions_to_functions_dict, based on the filename.
Call the relevant function from extensions_to_functions_dict based on the filename .
def open_any_workbook(filename):
    """Call the relevant function from extensions_to_functions_dict, based on the filename."""
    file_has_valid_extension = False
    if '.' in filename:
        extension = filename.split('.')[-1]
        if extension in valid_extensions:
            file_has_valid_extension = True
            function_to_open_workbook = extensions_to_functions_dict[extension]
            with function_to_open_workbook(filename) as workbook:
                yield workbook

    if not file_has_valid_extension:
        error = 'File {} does not have a valid extension. Valid extensions are: {}'.format(
            filename,
            ', '.join(valid_extensions),
        )
        raise SpreadsheetFileExtError(error)
def open_any_workbook ( filename ) : file_has_valid_extension = False if '.' in filename : extension = filename . split ( '.' ) [ - 1 ] if extension in valid_extensions : file_has_valid_extension = True function_to_open_workbook = extensions_to_functions_dict [ extension ] with function_to_open_workbook ( filename ) as workbook : yield workbook if not file_has_valid_extension : error = 'File {} does not have a valid extension. Valid extensions are: {}' . format ( filename , ', ' . join ( valid_extensions ) , ) raise SpreadsheetFileExtError ( error )