Reputation:
I want to create an array from the data I got from my database.
My database looks something like this:
name, age, height, birth_month
John, 57, 2.11, April
Rico, 57, 1.05, June
Max, 57, 1.50, December
Lisa, 35, 1.23, July
Beth, 21, 1.66, July
Luna, 89, 2.3, July`
Now I want an array excluding name
and putting birth_month
first.
Here is the array I want to create:
data = [[April, 57, 2.11],
[June, 57, 1.05],
[December, 57, 1.50],
[July, 35, 1.23],
[July, 21, 1.66],
[July, 89, 2.3 ]]
So what I tried to do was this:
mycursor = mydb.cursor()
mycursor.execute("SELECT birth_month, age, height FROM customers")
print(mycursor.fetchall())
But this is not exactly what I want. How can I get an array formatted, just as I want?
This is what I get:
[[(u'April', Decimal('57'), Decimal('2.11')),
(u'June', Decimal('57'), Decimal('1.05')),
(u'December', Decimal('57'), Decimal('1.50')),
(u'July', Decimal('35'), Decimal('1.23')),
(u'July', Decimal('21'), Decimal('1.66')),
(u'July', Decimal('89'), Decimal('2.3'))]]
What I want is that the "Decimal" and "u'" dissapears, and that every row has seperate [].
Upvotes: 0
Views: 2028
Reputation: 113988
mycursor.execute("SELECT name,age,height FROM customers")
print(mycursor.fetchall())
Upvotes: 2