开发者

Python/mysql: Result into two Lists

开发者 https://www.devze.com 2023-03-27 08:56 出处:网络
I was trying to plot MySQL result using Python script and matplotlib import MySQLdb import matplotlib.pyplot as plt

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号