2

I am a newbie at Python, and wading through the various peculiarities of the language. One of the peculiarity I found is the output of the following code snippet:

qry = 'SELECT COUNT(*) FROM <<TABLE>>'
cursor.execute(qry)
rowCounts = cursor.fetchone()
print("The number of rows in the <<TABLE>> table : {}".format(rowCounts))

I am getting the following output on my terminal:

Connected to the MySQL database.
The number of rows in the <<TABLE>> table : (150L,)

I am stumped by the brackets and the comma. I have searched for the answer to explain the occurrence, but haven't found any plausible explanation for the format. Is there something I should be doing differently?

All help is appreciated.

1
  • What database/ORM (i.e. SQLAlchemy)? What's the output of type(rowCounts) and type(rowCounts[0])? I suspect it's a tuple containing a Long Commented Dec 28, 2012 at 4:08

1 Answer 1

3

The output you see is because the rowCounts is a tuple containing only 1 element.

a tuple with one item is constructed by following a value with a comma

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. I believe I made a boo-boo. I was trying to use a method to get the information for which I should have been using an attribute. Now, off I go to learn more about tuple.

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.