The dimensions of a tuple

B

bg_ie

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?

Thanks,

Barry.
 
J

John Machin

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
 
B

bg_ie

I wish to pass an argument to a function which will inset rows in a
db. I wish to have the follow possibilities -

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top