import pymysql connect = pymysql.connect(user = 'm', password = 'M', db = 'x', host = 'rm', port = 3306, charset = 'utf8' ) con = connect.cursor() bu=0 buu=0 def du(ab): sql="select count(*) from {} where bzz='0'".format(ab) try: count1=con.execute(sql) connect.commit() except: connect.commit() count2=con.fetchall() if count2[0][0]<10: sql1="update bm51 set bzz='0'" con.execute(sql1) connect.commit()