Danny J.
Danny J.

Reputation: 39

How to get only string from mysql result?

I need to get the string out of mysql result query

mycursor.execute("Select text from text_table")
myresult = mycursor.fetchall()
rows=[i[0] for i in myresult]
for x in myresult:
    print(x[0])

It only returns one row but it returns in this format:

(u'I need this string',)

I tried this

rows=[i[0] for i in myresult]
print(myresult)

Upvotes: 1

Views: 425

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521437

I think your syntax is off. Try this version:

mycursor.execute("Select text from text_table")
myresult = mycursor.fetchall()
for row in myresult:
    print(row[0])

The offending line of code might be this:

rows=[i[0] for i in myresult]

This appears to be consuming the cursor by iterating through the entire result set.

Upvotes: 1

Related Questions