0

I'm currently using an example to select a variable from MySQL via Python. For this I'm using the MySQLdb import.

It all works great, I'm able to get the value from MySQL but when I print the result, it returns as:

('text',)

Is there a way to get this to just show up as

text

The code I'm working with is:

try:
        cursor.execute("""SELECT value FROM settings WHERE name='text'""")
        results = cursor.fetchone()
        print results

Thank you!!

1 Answer 1

2

Python 3 :

print(results[0])

Python 2 :

print results[0]

This will take the first and only element of the tuple, which is 'text', and printing a string will just write text without quotes in the console.

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

Comments

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.