我有多个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()
query_str = query_str + and + Project_Attr_Sensor + ' == ' + self.dlg.comboBox1.currentText()
此行的语法不正确,其他语法相同,但是您能解释一下您要做什么吗?