• [^] # Re: Moult remarques

    Posté par . En réponse au message Python: Return value not found in function. Évalué à 3. Dernière modification le 31 mars 2021 à 07:53.

    Et encore même chose pour plus haut, je pense :

     for j in range(len(history)):
     if (message["email"] in history[j]):
     if history[j][2] == "no": # Question and then customer_id
     questions_2 = eval(history[j][3].replace("$",","))
     if order_info != {}:
     response, answer_id = detect_response(shop,questions_2,order_info,message,history)
     history[j][2] = order_info["customer_id"]
     elif "not_customer" in questions and "status" in questions_2:
     question_2 = ["status","not_customer"]
     order_info_2 = {"status":"none","time":400,"order_time":400}
     response, answer_id = detect_response(shop,questions_2,order_info_2,message,history)
     else:
     response = "/ALERT I could not find info on this customer"
     answer_id = "s9"
     elif order_info != {}:
     response, answer_id = detect_response(shop,questions,order_info,message,history)
     else:
     response = "/ALERT I could not find info on this customer"
     answer_id = "s9"
     answer_ids = list(eval(history[j][4].replace("$",",")))
     if answer_id not in answer_ids:
     answer_ids.append(answer_id)
     else:
     return "/ALERT This customer often asks me the same question", "/ALERT"
     history[j][4] = str(answer_ids)
     lst = [] #rebuild the file content
     for lst3 in history:
     lst.append(",".join(lst3))
     cont = "\n".join(lst)
     file = open("shops/{}/history.csv".format(shop),"w")
     file.write(cont)
     file.close()
     return response, answer_id

    peut devenir :

     for j in range(len(history)):
     if (message["email"] in history[j]):
     return handle_email(X, Y, Z) # toujours pareil...

    Ce qui donne la fonction :

     def build_answer(shop,order_info,message,questions,history,is_buffalo):
     questions_2 = ["info_not_found","none"]
     history_line = None
     for j in range(len(history)):
     if (message["email"] in history[j]):
     return handle_email(X, Y, Z) # toujours pareil...
     response, answer_id, info = prepare_response(paramA, paramB) # ajuster les params
     # Build the file content
     log_response(param1, param2) # mettre les paramètres nécessaires
     return response, answer_id

    Un peu plus clair, non ?

    Note : prendre aussi en compte les remarques précédentes

    Note 2 : les opérations de log peuvent être factorisées également... toujours même raison.

    Matricule 23415