Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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])
     
       
       con.commit()

Items is some Id´s like:

18,17,83,14

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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(',')]
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading