How to Iterate through cur.fetchall() in Python

前端 未结 5 931
刺人心
刺人心 2021-01-02 18:18

I am working on database connectivity in Python 3.4. There are two columns in my database.

Below is the query which gives me all the data from two columns in shown f

5条回答
  •  遥遥无期
    2021-01-02 18:46

    looking at

    [('F:\\test1.py', '12345abc'), ('F:\\test2.py', 'avcr123')]
      i              j                 i            j
    

    you are taking a strings i and j and indexing it like

       print(row['F:\\test1.py'])
        print(row['12345abc'])
    

    which gave you typeError

    TypeError: string indices must be integers
    

    this is because i in data is a string and your a indexing this

    try this

    for i,j in data:
        print(i)
        print(j)
    

提交回复
热议问题