for loop
Hi all, I tryed to code something in pyhton, but have a challenge with a for loop. the function "find_CUA_in03" works well on the fist iteration, it picks up the "condition" from vlookup_obj and find the correct items in the "read_object" and they are wroten correctly in the "write_obj", but when "condition" chenge on second cycle it seems the "write_with_condition" is not run. I know there are milion of ways to do the same but if you would like to help me please stay with the code <i wrote below: def write_with_condition(read_obj, write_obj, condition): # """ In a file, find the lines with "condition" and write in an other file""" for line in read_obj: if condition in line: write_obj.write(line) print(line) def find_CUA_in02(original_file, condition): # Create name of dummy / temporary file only_CUA = original_file + '_CUA.txt' # Open original file in read only mode and dummy file in write mode with open(original_file, 'r') as read_obj, open(only_CUA, 'w') as write_obj: # Line by line copy data from original file to dummy file write_with_condition(read_obj, write_obj, condition) def find_CUA_in03(original_file, lookup_file): # Create name of dummy / temporary file only_CUA = original_file + '_CUA.txt' # Open original file in read only mode and dummy file in write mode and lookup file in read mode with open(original_file, 'r') as read_obj, open(only_CUA, 'w') as write_obj, open(lookup_file, 'r') as lookup_obj: for line in lookup_obj: condition = line[9:18] print(line[9:18]) write_with_condition(read_obj, write_obj, condition) https://code.sololearn.com/c6On8D4Sdf56