首页 > 解决方案 > 如何访问和打印在另一个函数中使用的变量并评估为 True

问题描述

我有用 Python 编写的开源 Web 服务器。在服务器内部,我有一个wrong_checker()函数,它接受一个值并根据real_value检查它。我可以访问此功能。

def wrong_checker(value_of_check):
    return (value_of_check == "" or (not value_of_check and real_value)) \
           or value_of_check != real_value

现在我想编写函数find_value()来查找并打印real_value的值。

def find_value():
        ???????

标签: pythonserverboolean

解决方案


好吧,通常你应该写一个比较器函数

def compare(value_a, value_b):
    #compare stuff and return 1, 0 or -1
    #1 for value_a greater, 0 for equal and -1 for value_b greater

那你就更灵活了。


推荐阅读