如何使用字符串/变量连接多个条件

问题描述 投票:-2回答:1

我有多个if条件,如果满足每个条件,则需要将其添加到字符串/变量query_str中。但是我找不到正确的语法来添加“ and”条件和等于,从而无法正确生成查询。

query_str = ""

if self.dlg.Sensor_CB.currentText() != "Select":

    query_str = query_str + and + Project_Attr_Sensor + ' == ' + self.dlg.comboBox1.currentText()

if self.dlg.Scale_CB.currentText() != "Select":

    query_str = query_str + and + Project_Attr_Scale + ' == ' + self.dlg.comboBox2.currentText()

if self.dlg.Film_CB.currentText() != "Select":

    query_str = query_str + and + Project_Attr_Film + ' == ' + self.dlg.comboBox3.currentText()

if State_Poly_Attr.capitalize() == selectedStateName.capitalize() and Project_Attr_State == selectedStateName.capitalize() + query_str:

这不起作用:

if State_Poly_Attr.capitalize() == selectedStateName.capitalize() and Project_Attr_State == selectedStateName.capitalize() + query_str: 

这正在工作

if State_Poly_Attr.capitalize() == selectedStateName.capitalize() and Project_Attr_State == selectedStateName.capitalize() and Project_Attr_Sensor == self.dlg.comboBox1.currentText() and Project_Attr_Scale == self.dlg.comboBox2.currentText() and Project_Attr_Film == self.dlg.comboBox3.currentText()
python pyqt pyqt5
1个回答
0
投票
query_str = query_str + and + Project_Attr_Sensor + ' == ' + self.dlg.comboBox1.currentText() 

此行的语法不正确,其他语法相同,但是您能解释一下您要做什么吗?

© www.soinside.com 2019 - 2024. All rights reserved.