I'm trying to teach myself Python but I've hit a brick wall. I need to get a field from MySQL however when I retrieve the data from the database it comes out odd. That's the code below I use.
cursor1 = db.cursor()
cursor1.execute("select djname from jerryins_djleaderboard.leaderboard where djname = %s", dj)
result = cursor1.fetchall()
print result
It prints out like this:
(('cutecrazygirl88\r\n',)
However I want it to come out as cutecrazygirl88 as it is in the database. Any help would be appreciated. Thank you in advance!
fetchall()
returns all fields and all rows in the cursor. You will need to iterate over the rows and access the fields in order to get at the data.
for row in result:
print row[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With