Reputation: 1015
I am trying to print out data from my database in python using the mySQL connect library. I want to print out all of the tuples in a specific table, however, it is not coming out how I would like. Right now each tuple is printing out like this:
(u'User1',)
(u'User2',)
(u'User3',)
And I would like it just to print out as
User1
User2
User3
Below is my python function:
def show_player_table():
query = ("SELECT name FROM field_player")
cursor.execute(query)
for result in cursor:
print("{}".format(result))
Any ideas? I hope I have provided enough info
Upvotes: 0
Views: 129
Reputation: 700
Extract the first object of the tuple; I would even check if the tuple has any object:
def show_player_table():
query = ("SELECT name FROM field_player")
cursor.execute(query)
for result in cursor:
if len(result):
print("{}".format(result[0]))
Upvotes: 2