0

Sorry this question is so badly worded. Basically, I have a highscore column in my database, and I want to query the database for these values in descending order. This is how I so this:

highscore_list = ("SELECT highscore FROM users ORDER BY highscore DESC")
cursor.execute(highscore_list)
results = cursor.fetchall()
for i in results:
    print(i)

The values I have in the highscore column are 0, 0, 1000. When I run this code I get an output of (1000,) (0,) (0,) Is there way to remove the brackets and comma so I am instead left with 1000 0 0. I am using python and mysql.

1
  • This does not work :/ Commented Jul 14, 2020 at 16:18

1 Answer 1

1

You can see here to find out why that is caused and how it can be fixed within your code - mysql remove brackets from printed data

You can also, since cursor.fetchall() returns an iterable list, you can simply modify the values in a pythonic manner.

For example,

lst = [(1000,) , (0,) , (0,)]
correct = [str(x)[1:-2] for x in lst ]
results = list(map(int, correct))
print(results)

outputs:

root@00973a947f4e:/root# python app.py
[1000, 0, 0]
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.