determining the bounds of a tuple returned from a database
Fredrik Lundh
fredrik at pythonware.com
Fri Nov 17 03:33:37 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.
from python's perspective, the data structure you're looking at looks
like
tuple of
tuple of
one string
tuple of
one string
tuple of
one string
etc
so len(result) is the number of tuples, and len(result[index]) is the
number of strings in the inner tuples (=1). to get at an individual
string, do
s = result[index][0]
to look inside the string, you need to apply the appropriate string
operations to extract the data, or split it up in some suitable way.
there's no way Python can figure out how a string appears to you; from
Python's perspective, it's just a bunch of characters.
</F>
More information about the Python-list
mailing list