How to use *args when i only have 1 string?

63 views Asked by At

So lets say i have a python function like this:

def function_name(*param1, param2):
   ...

And i have a string "120,220,400". Is there a way i can place it in param1 without transforming it to a tuple of lists/other tuples? i tried using .split(',') but i just end up having ["120","220","400"].

I still want to use *param1 and dont really want to change the function, i am just developing a ui where the value read in the label comes out with a string "120,220,400"

1

There are 1 answers

4
Jasmijn On

If you have a variable my_var = "120,220,400", you can call your function like so:

function_name(*my_var.split(','), param2=whatever)

The * unpacks the list returned by str.split into different parameters, which then get packed back up into a single tuple.