【发布时间】:2014-06-08 19:47:20
【问题描述】:
基本上,我是从表中返回数据:
>mysql> SELECT x,y FROM xandy;
>+------+------+
>| x | y |
>+------+------+
>| 5 | 2 |
>| 4 | 6 |
>| 7 | 6 |
>| 4 | 6 |
>| 8 | 7 |
>| 4 | 6 |
>| 11 | 33 |
>| 33 | 22 |
>+------+------+
>8 rows in set (0.00 sec)
(抱歉格式不好)
def fetch():
try:
db = MySQLdb.connect("localhost",user="root",passwd="****",db="logger")
cursor=db.cursor()
SQLString = "SELECT x,y FROM xandy;"
cursor.execute(SQLString)
rows=cursor.fetchall()
return rows
db.close()
但是,当我得到返回值时,我会以以下格式将其全部放在一行中:
((5.0, 2.0), (4.0, 6.0), (7.0, 6.0), (4.0, 6.0), (8.0, 7.0), (4.0, 6.0), (11.0, 33.0), (33.0, 22.0 ), (6.0, 4.0))
有没有办法以简单的表格形式显示它,即带有 x 和 y 的两列? (ps我将在这一步之后使用gnuplot)
【问题讨论】:
-
附带说明:您的
db.close()永远无法到达。