[mod_python] mod_python & MySQLdb question

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Wed Dec 17 09:40:52 EST 2003


hi Giampiero, instead of print or echo, you use return or req.write.  I
had a similar question here:

http://www.modpython.org/pipermail/mod_python/2003-June/003263.html

I hope that helps you.

On Wed, 17 Dec 2003, Giampiero Benvenuti wrote:

> 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
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>




More information about the Mod_python mailing list