python - 如何访问和打印在另一个函数中使用的变量并评估为 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():
???????
解决方案
好吧,通常你应该写一个比较器函数
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
那你就更灵活了。
推荐阅读
- python - conda和pip的pytorch安装问题
- vba - MS Access 使用 Combo-Box 值作为查询条件
- jquery - jQuery:用于比较各种列表项中的文本的变量
- c++ - 一副牌输出错误
- javascript - jQuery async/await Ajax 调用,没有在 HTTP <> 200 上触发异常?
- swift - swift 11 中的秒表应用程序(编码世界的新手)
- reactjs - 如何在 React 中 .map 呈现分组到类别中的项目列表
- c++ - C ++ RoundUp 就像 Excel 中的地板的负数和正数的 ceil
- python - 为 pip 配置 Python C 扩展
- python - 如何在 Swift 中运行 tf2.0 模型