Reputation: 1
mycursor = mydb.cursor()
sql = "select electricityBalance from users"
mycursor.execute(sql)
print (int(record[0]) for record in mycursor.fetchone())
but the output gives this <generator object at 0x0000000002CFF2A0>
Upvotes: 0
Views: 314
Reputation:
According to this post, a generator expression is a "naked" for
expression.
That is why you are getting <generator object at 0x0000000002CFF2A0>
:
What you can do is this:
l1=[int(record[0]) for record in mycursor.fetchone()]
print(*l1)
Unpack a list.
You can also use .join
method, but keep in mind that it requires elements which are strings.
print(','.join(str(int(record[0])) for record in mycursor.fetchone()))
Upvotes: 1