[mod_python] mod_python & MySQLdb question

Giampiero Benvenuti giampiero.benvenuti at chiaroscuro.com
Wed Dec 17 18:31:39 EST 2003


Hello to all of you,

I'm quite intrigued by mod_python and the difference with "normal" 
python cgi...

for instance: I can't make this great pice of code (Jaroslaw Zabiello, 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/171463) wich 
works great in my cgi-bin directory, working with mod_python.

The problem I have is right at the end, when I have to deal with:

  for row in rows:
     print row['name'], row['txt']

The question is: how can I translate this last part of code to make it 
working with mod_python?

the great code:
----------------------------------
import MySQLdb
import MySQLdb.cursors

conn = MySQLdb.Connect(
     host='localhost', user='root',
     passwd='', db='test',compress=1,
     cursorclass=MySQLdb.cursors.DictCursor) # <- important
cursor = conn.cursor()
cursor.execute("SELECT name, sometext txt FROM foo")
rows = cursor.fetchall()
cursor.close()
conn.close()

for row in rows:
     print row['name'], row['txt'] # bingo!
------------------------------------

any help is much appreciated.

Thanks,

Giampiero



More information about the Mod_python mailing list