DXOracle / PyADO - convert lists of tuples to list of lists
Gerhard Häring
gerhard.haering at gmx.de
Fri Dec 13 21:44:37 EST 2002
* Harald <simon.12.ghum at spamgourmet.com> [2002-12-14 02:40 +0100]:
> Hello,
>
> I built an application with PyADO, connecting to oracle.
>
> Now a kind member of this newsgroup sent me prebuilt binaries of
> DXOracle, and I tried to exchange PyADO with DXOracle.
:-)
> But:
>
> when doing a query, PyADO returns a list of lists, like
> [["James","Curtis","singer","somewhere"],
> ["Sandra","Bullock","actress","ny"]]
>
> DXOracle returns a list of tuples
> [("James","Curtis","singer","somewhere",),
> ("Sandra","Bullock","actress","ny",)]
>
> So my application stumbles because of minor differences between lists and
> tuples.
Lists are mutable, tuples aren't. Tuples are also hashable (because
they're immutable). Unless your app depends on one of these properties,
it shouldn't 'stumble'.
> To convert I can do:
> [complicated way snipped]
> .. but it seems very ugly ... to move that much data around. Isn't there
> a faster & more elegant way?
To convert a list (or any sequence) to a tuple, use
tuple(seq)
Similarly, to convert a tuple (or any sequence) to a list, use
list(seq)
It's really as easy as that.
ciao,
-- Gerhard
More information about the Python-list
mailing list