MySQL adapter question

Pop Tufty poparosa at aol.com
Tue Sep 12 03:56:05 CEST 2000


Jeff,

    Thanks, that did the trick.  I am glad that
that this is a great news group.  Is there a place I can
go to find  code snippets such as this?  Seems like there
should be a spot I could grep for said snippets.

thanks again - pop

Jeff Bauer wrote:

> Pop,
>
> You're using an older MySQL interface.  You might want
> to check Andy Dustman's version, since it is better
> supported.
>
>   http://dustman.net/andy/python/
>
> Anyhow, here's some (untested) code using the old
> interface:
>
>     STH = DBH.query("select Measurement from tablea")
>     fields = map(lambda x: x[0], STH.fields())
>     for row in STH.fetchrows():
>         for i in range(len(fields)):
>             print "field %s is %s" % (fields[i], row[i])
>         print  # print blank line separator
>
> Regards,
>
> Jeff Bauer
> Rubicon Research
>
> Pop Tufty wrote:
> > DBH = MySQL.connect() # localhost
> > DBH.selectdb("mydb")
> > STH = DBH.query("select Measurement from tablea")
> > for i in STH.fetchrows():
> >     print "field data is "
> >     print STH.data[i]
> >
> > The STH.data[i] line does not work.  What do
> > I put there to iterate along the values returned from
> > the query?




More information about the Python-list mailing list