Oden Ikpi David
Oden Ikpi David

Reputation: 31

Cursor returns <sqlite3.Cursor object at 0x033A21E0> instead of returning the object itself

When i run this code on the db browser it displays the price, but it returns the position on my console when i run it in python.

price = c.execute("SELECT Selling_Price FROM stock_records
        WHERE  Product_Name ='popcorn'")
print(price)

Upvotes: 0

Views: 13475

Answers (2)

John Gordon
John Gordon

Reputation: 33310

As @Matthias commented, execute() does not return query results directly; you must fetch the results from the cursor object.

Try this:

c.execute("SELECT Selling_Price FROM stock_records WHERE  Product_Name ='popcorn'")
print (c.fetchone())

If you expect the query to return more than one result row, use fetchall() instead of fetchone().

Upvotes: 1

zmike
zmike

Reputation: 1180

You have to retrieve the item (or list of items) that have been returned. As an example:

price = c.execute("SELECT Selling_Price FROM stock_records
        WHERE  Product_Name ='popcorn'")
price = c.fetchone()
print(price)

More info can be found in the Python documentation.

Upvotes: 5

Related Questions