MySQL adapter question
Pop Tufty
poparosa at aol.com
Tue Sep 12 14:05:17 EDT 2000
OK, I searched the python.faqts for this seemingly simple
issue and came up empty:
I got the data from the database, thank you, and I want to
graph it, so I think -- That's easy, use string.atoi(row[i])
to get what I want - no dice. When I use the atoi above, I get
TypeError: argument 1: expected string, int found
When I try to pass row[i] directly to my function (see below) to
map an integer to a y value, it looks like it thinks it is a string...
this_y = percent_to_y(row{i])
TypeError: bad operand type(s) for /
def percent_to_y(percent):
retval = bot - ygap - ((percent * ygap) / 10)
return retval
What is going on?
Steve Holden wrote:
> FAQTS (http://python.faqts.com) is one quite good place for Python
> code snippets. I suspect thare are others as well.
>
> regards
> Steve
>
> Pop Tufty wrote:
> >
> > 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?
>
> --
> Helping people meet their information needs with training and technology.
> 703 967 0887 sholden at bellatlantic.net http://www.holdenweb.com/
More information about the Python-list
mailing list