string - Transform string into IF argument
问题描述
How to transform a string into a logical argument in Python, to be inserted as an argument of the if()
function?
For example:
string = "(A != 0) and (B >= 5)"
How can this string be transformed into the very logic that it represents so that it can be inserted into an if()
function?
解决方案
您可以使用 eval 函数来评估字符串:
string = "(A != 0) and (B >= 5)"
if eval(string):
doSomething()
推荐阅读
- c# - 从 c# 表单应用程序发布到 api 时,我无法将数据发送到日期时间
- android - 任务':fluttertoast:compileReleaseKotlin'Catcher包flutter执行失败
- php - 如何在laravel中加入三个表
- jq - 以 json 格式从 shell 命令获取输出
- c# - StackedHeaderDecorator添加的多层列标题下如何添加行
- c++ - 我正在尝试使用 std::signal 干净地结束我的多线程程序,我做错了什么?
- amazon-web-services - 主集群故障时如何切换到 MirrorMaker 主题?
- arima - SARIMA 模型的初始值?
- excel - 无法运行 vba 功能
- iis - 如何在 IIS 中运行(内联)JS 和 CSS?