simple question on optional parameters

S

scooterm

I am using a toolkit that has a SetFaveNumbers() method. the method
accepts any number
of comma-separated numbers.

the following are all valid examples:

FooToolkit.SetFaveNumbers(1,3,5)
FooToolkit.SetFaveNumbers(2,4,6,8,10)
FooToolkit.SetFaveNumbers(1)

I do not know how this method is implemented, but I would like to be
able
to call the method using a single variable:

MyFaveNumbers = []
MyFaveNumbers.append(2)
MyFaveNumbers.append(4)

FooToolkit.SetFaveNumbers(MyFaveNumbers)

how is this possible in python?
 
F

Fredrik Lundh

I am using a toolkit that has a SetFaveNumbers() method. the method
accepts any number of comma-separated numbers.

any number of arguments, that is.
the following are all valid examples:

FooToolkit.SetFaveNumbers(1,3,5)
FooToolkit.SetFaveNumbers(2,4,6,8,10)
FooToolkit.SetFaveNumbers(1)

I do not know how this method is implemented, but I would like to be
able to call the method using a single variable:

MyFaveNumbers = []
MyFaveNumbers.append(2)
MyFaveNumbers.append(4)

FooToolkit.SetFaveNumbers(MyFaveNumbers)

try:

FooToolkit.SetFaveNumbers(*MyFaveNumbers)

</F>
 
D

D H

I am using a toolkit that has a SetFaveNumbers() method. the method
accepts any number
of comma-separated numbers.

the following are all valid examples:

FooToolkit.SetFaveNumbers(1,3,5)
FooToolkit.SetFaveNumbers(2,4,6,8,10)
FooToolkit.SetFaveNumbers(1)

I do not know how this method is implemented, but I would like to be
able
to call the method using a single variable:

MyFaveNumbers = []
MyFaveNumbers.append(2)
MyFaveNumbers.append(4)

FooToolkit.SetFaveNumbers(MyFaveNumbers)

See if this works:
FooToolkit.SetFaveNumbers(*MyFaveNumbers)

The asterix unpacks a list or tuple into individual items.
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top