【问题标题】:Python/mysql: Result into two ListsPython/mysql:结果分为两个列表
【发布时间】:2011-08-10 18:44:08
【问题描述】:

我试图使用 Python 脚本和 matplotlib 绘制 MySQL 结果

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

我将通过像这样的简单传递来绘制这两个列表

id,ts=zip(*row)  #cThis will solve the problem


plt.plot(id,secondid)
plt.grid()

但是我很困惑创建两个列表,因为查询结果是一个元组列表。 请建议。

【问题讨论】:

  • 留下这个问题。我得到了答案 id,secondid=zip(*row)
  • 如果你已经解决了,请将解决方案作为答案发布,而不是评论,并接受它。
  • 对不起。我不知道这东西是新手。我已经提交了答案。谢谢

标签: python matplotlib


【解决方案1】:

答案是

id,secondid=zip(*row)

【讨论】:

    猜你喜欢
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 2017-07-05
    • 1970-01-01
    相关资源
    最近更新 更多