I would like to keep track of the steps taken by the program in a text report file. Each step in the code returns a dataframe and there is a dependency between tasks (task n cannot be executed if task n-1 had found nothing).
My programme looks like this:
(kind of pseudo code)
import pandas as pd
step_1 = find_stuff()
if not step_1.empty:
step_2 = find_new_stuff()
if not step_2.empty:
step_3 = find_new_stuff_again()
if not step_3.empty:
report (step_1, step_2, step_3)
else:
report (step_1, step_2, step_3=pd.DataFrame())
else:
report (step_1, step_2=pd.DataFrame(), step_3=pd.DataFrame())
else:
report (step_1=pd.DataFrame(), step_2=pd.DataFrame(), step_3=pd.DataFrame())
def report (step_1, step_2, step_3) :
report_file = open("report.txt", "a")
if not step_1.empty:
report_file.write(f'Here what was found for step 1 \n : { step_1} \n')
if not step_2.empty:
report_file.write(f'Here what was found for step 2 \n : { step_2} \n')
if not step_3.empty:
report_file.write(f'Here what was found for step 3 \n : { step_3} \n')
else:
report_file.write('Nothing was found \n')
This way of doing things is very basic but does what I ask it to do. Though, I was wondering if there was a way to avoid/reduce all these "if" or an alternative way to generate this kind of report?