2

im trying to print count table in python, im write this code:

count = cur.execute("SELECT COUNT(*) FROM %s;" str(table))
print count

all print results is 1, (think 1 = true), how i can print the real result of my sql command ?

thanks

1 Answer 1

3

You must fetch the result:

cursor = db.cursor()
count = cursor.execute("SELECT COUNT(*) FROM " + str(table))
db.commit()
print cursor.fetchone()[0]
cursor.close()
Sign up to request clarification or add additional context in comments.

2 Comments

count = (1332L,) what is 1332L ? i need number result !
fetchone returns a tuple. I've added [0] so you can print just the number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.