determining the bounds of a tuple returned from a database

mensanator at aol.com mensanator at aol.com
Fri Nov 17 12:48:24 EST 2006


ronrsr wrote:
> very sorry, that was my error - len(result[0]) and len(result[1]) both
> return 1 --
>
> i think I'm misunderstanding what len() does - to me they appear to
> have 2 or 3 elements, or at least be composed of a string of some
> length.

One string composed of multiple data elements means
the problem is in your database design, not in your Python code.

>
> I guess len() isn't the function i'm looking for then.  How do I tell
> how many strings, or how many bytes are in each dimension?

You have to split the strings based on some delimiter, but your
delimiters seem inconsistent. Unless the different delimiters actually
have different meanings which, again, implies bad database design.

> so that I
> can iterate through them.
>
> Each entry in that list is a keyword - Alternately, is there any fast
> way to parse that into a sorted list of distinct keywords.

That could easily be done in the database itself, but only if it is
designed properly.

>
> very sorry for the error.
>
> bests,
>
> -rsr-
>
> Fredrik Lundh wrote:
> > ronrsr wrote:
> >
> > > it looks like the  len() function is the one I want.
> > >
> > > for:   len(result) - i get 248,
> > >
> > > but for len(result[0]) or len(result[1]) i always get 0.
> >
> > that's a bit surprising, because both items are tuples that contain
> > exactly one item:
> >
> > >> (('Agricultural subsidies; Foreign aid',), ('Agriculture; Sustainable
> > >> Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood
> > >> Development, Birth Defects; Toxic Chemicals',),
> > 
> > </F>




More information about the Python-list mailing list