How can i itenerate int´s and insert into sql

Im trying to use a for loop the get the Id´s and update in the table the state of the product. Right now have this code:

for row in range(self.tableLinhaNova.rowCount()): 

    _item = self.tableLinhaNova.item(row, column) 
    if _item:            
        items1 = self.tableLinhaNova.item(row, column).text()
        items= int(items1)
    for item in items:
       cursor.execute("""UPDATE "Teste" SET "Estado"= 2 WHERE "IdTeste" = %s""",[item])

Items is some Id´s like:


But it doesn´t work, i am getting this error:

TypeError: 'int' object is not iterable

I´m new in python, so i probably did something wrong can anyone help please!.

>Solution :

items= int(items1) will either assign some integer to items (if items1 can be interpreted as an integer by Python) or raise a ValueError. In your situation, it’s obviously the former case. I’d assume that items1 is a string representing a single number.

Maybe you’d need something like:

items1 = self.tableLinhaNova.item(row, column).text()
items = [int(i) for i in items1.split(',')]

Leave a Reply