I was trying to plot MySQL result using Python script and matplotlib
import MySQLdb
import matplotlib.pyplot as plt
conn = MySQLdb.connect (host = "localhost",
user = "testuser",
passwd = "testpass",
db = "test")
cursor = conn.cursor ()
cursor.execute ("SELECT id,secondid from table limit 10")
row = cursor.fetchall()
print "RESULT:", row[0]
cursor.close ()
conn.close ()开发者_运维百科
And i will plot these two lists by simple passing like this
id,ts=zip(*row) #cThis will solve the problem
plt.plot(id,secondid)
plt.grid()
But i am quite confused to create two lists since The query result is a list of tuples. Please suggest.
The answer is
id,secondid=zip(*row)
精彩评论