for item in l:
sql = "select id from t_ci_simple_info where host=%s and metric=%s"
r=cursor.execute(sql,(item[0],item[1]))
if r:
id_r=cursor.fetchall()
self.simple_table_id[item[0] + '_' + item[1]] = int(id_r[0][0])
l.remove(item)
db.commit()
有两个地方需要注意
1、语句查询部分
语句查询部分,像上边这种写法是可以使用的
sql = "select id from t_ci_simple_info where host=%s and metric=%s"%(item[0],item[1])
像这种就无法执行成功
2、对于列表对象如何删除指定元素
之前是用pop,但是pop需要指定索引或者不指定索引
想要移除指定元素,需要用remove