I'm trying to print the output of SQL output as below:
dwh_cur.execute("""select count (*) from sales""")
var1 = dwh_cur.fetchone()
text = 'Total Sales is ' + var1
var1 = 100
Expected output:
Total Sales is 100
But I get an error
TypeError: can only concatenate str (not "tuple") to str
Well dwh_cur.fetchone() returns a record which is represented as a tuple of n elements,
dwh_cur.execute("""select count (*) from sales""")
var1 = dwh_cur.fetchone()
text = 'Total Sales is {}'.format(var1[0])
Might work depending on what is returned form the query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With