Python[mod_wsgi]如何将所有mysql结果收集到一个数组中?

Python[mod_wsgi]如何将所有mysql结果收集到一个数组中?,python,python-2.7,mod-wsgi,wsgi,mysql-python,Python,Python 2.7,Mod Wsgi,Wsgi,Mysql Python,通过cli: [root@localhost 0]# python test13.wsgi (1, 'aaaaaa') (2, 'sdsdfsdfsd') (3, 'dsfsdfasdfsdf') (4, 'sdgsdgsdfsa') [root@localhost 0]# 通过apache: (4, 'sdgsdgsdfsa') 脚本代码: import MySQLdb conn = MySQLdb.connect (host = "localhost",

通过cli:

[root@localhost 0]# python test13.wsgi
(1, 'aaaaaa')
(2, 'sdsdfsdfsd')
(3, 'dsfsdfasdfsdf')
(4, 'sdgsdgsdfsa')
[root@localhost 0]# 
通过apache:

(4, 'sdgsdgsdfsa')
脚本代码:

import MySQLdb
conn = MySQLdb.connect (host = "localhost",
                        user = "root",
                        passwd = "",
                        db = "aaa")
cursor = conn.cursor ()
cursor.execute ("select * from bbb limit 10")
numrows = int(cursor.rowcount)
for i in range(numrows):
    row =  cursor.fetchone()
    print row
cursor.close ()
conn.close ()

def application(environ, start_response):
    start_response('200 OK', [('content-type', 'text/html')])
    return [repr(row)]
我想简单地将所有这些行放入一个数组中,就像php中一样 然后在python中与php进行print_r()等价

因此,在apache中打印的是所有内容,而不仅仅是 最后一个。

此代码:

for i in range(numrows):
    row =  cursor.fetchone()
row
设置为
cursor.fetchone()
numrows
次的结果。它没有列出一个清单

您可能只想编写
rows=cursor.fetchall()


此外,如果你想用Python编写一个简单的(或复杂的)Web应用程序,我会考虑查看./P>这很好,但是我不需要它在一个数组中,这样我就可以选择打印哪一个数组?这就是我得到的。。((1,'aaaaa')、(2,'sdfsdfsd')、(3,'dsfsdfasdfsd')、(4,'sdgsdgsdfsa'))我如何有选择地打印其中一个?@PythonNewbie:在跳入WSGI之前阅读Python教程。我会选择远离flask、django等,因为我认为只要我找到一种方法从mysql中获取一些东西,然后进行php apc等价内存缓存,我就不再需要太多来设计网页了。听起来不错,我想下一个问题将是如何打印特定的数组。