def my_reducer_simulation(output_directory, my_reducer_input_parameters): # 1. We create the map_simulation folder # 1.1. If it already existed, then we remove it if os.path.exists(output_directory + "3. my_reduce_simulation/"): shutil.rmtree(output_directory + "3. my_reduce_simulation/") # 1.2. We create it again os.makedirs(output_directory + "3. my_reduce_simulation/") # 2. We collect the list of files we have to process file_names = os.listdir(output_directory + "2. my_sort_simulation/") # 3. We process each file sequentially for file in file_names: # 3.1. We open the file to be read my_input_stream = codecs.open(output_directory + "2. my_sort_simulation/" + file, "r", encoding='utf-8') # 3.2. We open the file we want to write to my_output_stream = codecs.open( output_directory + "3. my_reduce_simulation/reduce_" + file, "w", encoding='utf-8') # 3.3. We process it my_reducer.my_reduce(my_input_stream, my_output_stream, my_reducer_input_parameters) # 3.4. We close the files my_input_stream.close() my_output_stream.close()
def my_reducer_simulation(output_directory, my_reducer_input_parameters): # 1. We create the file we will write to my_output_stream = codecs.open(output_directory + "my_reducer_results.txt", "w", encoding='utf-8') # 2. We open the source file my_input_stream = codecs.open(output_directory + "my_sort_results.txt", "r", encoding='utf-8') # 3. We process it my_reducer.my_reduce(my_input_stream, my_output_stream, my_reducer_input_parameters) # 4. We close the source file my_input_stream.close() # 5. We close the file my_output_stream.close()