Reputation: 389
Is there a way to pass the same parameter n times to a function?
For example:
if len(menu) == 1:
gtk.ListStore(str)
elif len(menu) == 2:
gtk.ListStore(str, str)
elif len(menu) == 3:
gtk.ListStore(str, str, str)
Something like this, but "automatic"...
Upvotes: 0
Views: 72
Reputation: 156158
I'm sure what you mean is:
gtk.ListStore(*menu)
Sequences can be splatted into the positional arguments of a function call. The splat must go at the end of positional arguments, ie:
foo(1, 2, *bar)
is OK, but you can't do
foo(1, *bar, 2)
Upvotes: 2
Reputation: 7944
def ListStore(*str_collection): #collect arguments passed into str_collection which is a tuple
for s in str_collection:
print(s)
ListStore("A","B","C")
Outputs:
>>>
A
B
C
str_collection
has type:
>>>
<type 'tuple'>
Upvotes: 1