python - pyqt5: passing extra arguments to pyqt slots when connecting in a loop -


can't understand why code shows me same result: i=4

for in range(0,5):     self.close_deal[i].clicked.connect(lambda:self.printme(i)) def printme(self,i):     print('i=',i) 

but when write as:

self.close_deal[0].clicked.connect(lambda:self.printme(0)) self.close_deal[1].clicked.connect(lambda:self.printme(1)) self.close_deal[2].clicked.connect(lambda:self.printme(2)) self.close_deal[3].clicked.connect(lambda:self.printme(3)) self.close_deal[4].clicked.connect(lambda:self.printme(4)) 

i receive different results


Comments

Popular posts from this blog

unix - grep command not match start of new line with another regex -

sql - calculate weighted average for each day and id based on time intervals in PostgreSQL -

Sort a complex associative array in PHP -