hel*_*kee 4 python typeerror python-3.x
我正在尝试打印 SQL 输出的输出,如下所示:
dwh_cur.execute("""select count (*) from sales""")
var1 = dwh_cur.fetchone()
text = 'Total Sales is ' + var1
Run Code Online (Sandbox Code Playgroud)
变量 1 = 100
预期输出:
Total Sales is 100
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误
TypeError: can only concatenate str (not "tuple") to str
Run Code Online (Sandbox Code Playgroud)
那么 dwh_cur.fetchone() 返回一个记录,它表示为 n 个元素的元组,
dwh_cur.execute("""select count (*) from sales""")
var1 = dwh_cur.fetchone()
text = 'Total Sales is {}'.format(var1[0])
Run Code Online (Sandbox Code Playgroud)
可能工作取决于从查询返回的内容。
| 归档时间: |
|
| 查看次数: |
15862 次 |
| 最近记录: |