0

I have created a table using SQLAlchemy with Python+Flask.

Let us call this table Table.

In table I have columns called Col_1, Col_2,....Col_n.

Is it possible for a given row to access the values in these columns in a for loop.

Here is what I tried:

row = Table.query.get(1) #returns the first row

for i in range(1, n+1):
    print(row.col_i)

But it throws an error that the attribute row_i does not exist.

How can I tell python that I want it to pull the value in col_i not search for the attribute col_i explicitly as this does not exist.

2
  • Perhaps print(row.col_ + i) Hope help you. Commented Apr 10, 2020 at 11:18
  • no this does not work. Commented Apr 10, 2020 at 11:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.