简体   繁体   English

python收集多个函数的返回值,并在一个非主函数处针对所有函数验证输入

[英]python gathering return value of multiple function and validate input against all function at one non-main function

I am looking for solution where I can make sure that input value tested against each function and returned for all error case. 我正在寻找可以确保输入值针对每个函数进行测试并针对所有错误情况返回的解决方案。

Here is my code. 这是我的代码。

def func_a(value):
   do something
   return

def func_b(value):
    do something
    return

def func_c(value):
    do something
    return

def final(value):
    A=def_a(value)
    B=def_b(value)
    C=def_c(value)
    if A != foo:
      return A
    elif B != foo:
      return B
    elif C != foo:
      return C
    else:
       return'Success'

    main()

       print final(value)

Problem: 问题:

I passing one file as a value where each line should be tested against certain test. 我将一个文件作为值传递,其中应针对某些测试来测试每一行。 Now if there is a issue in line which matches to def_a(), the def_a() will be executed but that line did not tested against remaining functions(fund_b, fund_c) due to if loop in def final(). 现在,如果一行中有一个与def_a()相匹配的问题,则将执行def_a(),但是由于def final()中的if循环,该行未针对其余功能(fund_b,fund_c)进行测试。

Question: 题:

Is there a way , I can craft a def final() such a way that each line tested for all functions and if that line match with more than one function then both conditions will be executed? 有没有一种方法,我可以设计def final()这样一种方式,即每行测试所有功能,并且如果该行与多个功能匹配,则将同时执行两个条件?

Store the function results in a dictionary and return it as needed: 将函数结果存储在字典中,并根据需要返回:

def final(value):
    result = {'A':def_a(value),
              'B':def_b(value),
              'C':def_c(value)}
    if any(item != foo for item in result.values()):
      return result
    else:
       return'Success'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM