title: Assigning a variable from SQL to Python
body: <p>I've managed to make this work except for the line <code>for i in int(num_rows[&quot;COUNT(*)&quot;]): </code></p>
  <p>With this i get a  <code>TypeError: list indices must be integers or slices, not str</code></p>
  <p>I checked with <code>for i in [0,1,2,3,4,5]</code> it updates the table however i get another error:
  <code>row_symbol = rows[i][&quot;symbol&quot;]</code>
  IndexError: list index out of range ```</p>
  <p>The main problem is, how do iterate over variable <code>rows</code> in the for loop?</p>
  <pre><code>    &quot;&quot;&quot;Show portfolio of stocks&quot;&quot;&quot;
      user_id = session[&quot;user_id&quot;]
      rows =db.execute(&quot;SELECT * FROM transactions WHERE id = :user_id ORDER BY symbol ASC&quot;, user_id=user_id)
      num_rows= db.execute(&quot;SELECT COUNT(*) AS n FROM transactions WHERE id = :user_id ORDER BY symbol ASC&quot;, user_id=user_id)
      if not rows:
          return apology(&quot;You don't have any stocks, maybe buy some.&quot;)
      user= db.execute(&quot;SELECT * FROM users WHERE id = :user_id&quot;, user_id = user_id)
      cash = user[0][&quot;cash&quot;]
  
      grand_total = cash
  
      for i in int(num_rows[&quot;COUNT(*)&quot;]):
          row_symbol = rows[i][&quot;symbol&quot;]
          for row_symbol in rows:
  
              symbol=lookup(rows[i][&quot;symbol&quot;])
              price = symbol[&quot;price&quot;]
              shares = rows[i][&quot;shares&quot;]
              total= shares * price
              db.execute(&quot;UPDATE transactions SET price = :price, Total=:total WHERE id=:user_id AND symbol=:symbol&quot;,
                         price=usd(price), total=total, user_id=user_id, symbol=rows[i][&quot;symbol&quot;])
              grand_total += cash
              if i ==5:
                  return False
  
  
  
  
      return render_template(&quot;index.html&quot;, rows=rows,  cash = cash, total=grand_total)
  </code></pre>