The dimensions of a tuple
John Machin
sjmachin at lexicon.net
Fri Jan 25 06:03:14 EST 2008
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
More information about the Python-list
mailing list