如何将输出格式化为表格

时间:2013-06-10 13:59:02

标签: python mysql

这是带有查询数据库的python代码

cursor.execute("""select count(distinct offering_name) as events
    ,count(learner) as learners 
    ,count(distinct learner) as unique_learner
    ,count(dropped) as dropped
    ,sum(trans_price) as trans_price
    from EMS_data where organization like 'eng%' and manager ='rakesh'""")

#result= cursor.fetchall()
for result in cursor:
    print result

结果将是这样的

(367L, 7200L, 4543L, 7200L, 3216157.0)

但我想要这样

+--------+----------+----------------+---------+--------------------+
| events | learners | unique_learner | dropped | trans_price        |
+--------+----------+----------------+---------+--------------------+
|    378 |     8092 |           5204 |    8092 | 3197704.0799999996 |
+--------+----------+----------------+---------+--------------------+

怎么办这样......请帮忙

1 个答案:

答案 0 :(得分:1)

我不明白你的问题,怎么了?输出格式?它是一个touple,您可以使用括号[ ]访问它们,并在内部放置索引,从0开始。

print result[0] #prints 367

然后你可以自己格式化。