[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

The dimensions of a tuple

Barry

1/25/2008 10:27:00 AM

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.
2 Answers

John Machin

1/25/2008 11:03:00 AM

0

On Jan 25, 9:26 pm, bg...@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

Barry

1/25/2008 12:06:00 PM

0

On 25 Jan, 12:03, John Machin <sjmac...@lexicon.net> wrote:
> On Jan 25, 9:26 pm, bg...@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!