我用Python进行了一个SQLite查询,如下所示:
SharesOwned = db.execute("SELECT SUM(Shares) FROM transactionTable WHERE Share='FB'")
print(SharesOwned)
if sharesOwned < sharesToSell:
return errorMessage("You don't own that many shares of FB")
它打印:
^{pr2}$然后它给我这个错误:
TypeError: "List indices must be integers or slices not str"
如何提取整数形式的数字?在
看起来sharesoowned是一个字典列表。在这种情况下,要返回股份数量,您需要执行以下操作:
sharesowed[0]访问列表的第一个元素,在本例中是字典{'SUM(Shares)':10}。现在您只需要按键查找值,在本例中是“SUM(Shares)”。在
另外,看起来你在sharesoowned中有一个错误,s应该大写。在
尝试以下更改: 更新您的查询:
然后共享访问:
^{pr2}$相关问题 更多 >
编程相关推荐