The dimensions of a tuple

bg_ie at yahoo.com bg_ie at yahoo.com
Fri Jan 25 07:05:37 EST 2008


On 25 Jan, 12:03, John Machin <sjmac... at lexicon.net> wrote:
> On Jan 25, 9:26 pm, bg... at yahoo.com wrote:
>
> > Hi,
>
> > I wish to pass an argument to a function which will inset rows in a
> > db. I wish to have the follow possibilities -
>
> > ("one","two")
> > (("one","two"),("three","four"))
>
> > The first possibility would mean that one row is added with "one and
> > "two" being its column values. The second possibility means that two
> > rows are added.
>
> > So to do this I need to establish the dimension of the duple. Is it a
> > one dimentional or two dimentional. How do I do this?
>
> isinstance(arg[0], tuple)
>
> ... but I wouldn't do it that way. I'd use a list of tuples, not a
> tuple of tuples, to allow for ease of building the sequence with
> list.append, and two functions:
>
> insert_one(("one", "two"))
> insert_many([("one", "two")])
> insert_many([("one", "two"), ("three", "four")])
>
> Which of those 2 functions calls the other depends on which you'd use
> more often.
>
> HTH,
> John

Thanks for the tip regarding the list of tuples!



More information about the Python-list mailing list