SQLite - Python - refer the table column in a loop

0

I'm doing a script in Python by accessing SQLite database. I made a For loop but I do not know how to get the value of a column in the table.

See the example:

cursor2 = cnx.cursor()
cursor2.execute("select * from despesas")
cursor2.moveToFirst()
cont = 0
lista = []
for (despesa) in cursor2:
    if permanente="S":
    elif:

I need to check if the value of the "permanent" column in the "expenses" table is "S" or "N". The "permanent" column is varchar (1). Then I'll switch to boolean. How do I?

    
asked by anonymous 18.12.2017 / 21:05

1 answer

0

When you type select * from despesas you are selecting all the columns in the expenses table. To select only a specific column, change * to the desired column name.

Then your for loop can look like this:

//Selecionando apenas a coluna "permanente" da tabela "despesas"
query = cursor2.execute("SELECT permanente FROM despesas")

for row in query:
    if row == 'S':
        código
    else:
        código
    
19.12.2017 / 12:09