0

I have a cursor in python which retrieve a row from a database:

crx5 = con.cursor()
crx5.execute('select colA, colB, colC from nr')
crx5.fetchall()

There is only 1 row and I don't know how to retrieve the column values in some variables like:

var1=colA value
var2=colB value
var3=colC value

Pleas help me!

Thanks

2
  • You haven't used fetchall() and that isn't valid python syntax. Please follow some tutorials e.g. this before asking. Though they use SQLite, the concepts are comparable. Commented Aug 31, 2018 at 18:21
  • yes, i've missed fetchall(). Commented Aug 31, 2018 at 18:35

1 Answer 1

1

Just assign each column in fetchall() to a variable:

crx5 = conn.cursor()
crx5.execute(f"select colA, colB, colC from nr ;")
        for colA, colB, colC in crx5.fetchall():
            print(colC, colB, colA) # column swapping as an example

If you want a list of each column, then just append each row's column to an empty list, e.g:

col1 = [] 
for cola, colb, colc in crx5.fetchall():
    col1.append(cola)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.