0

I have dictionaliy for variables of function.

x = {"reverberance":20,"hf_damping":10}

Now I want to give the contents of x to this funciton.

def reverb(self,
       reverberance=50,
       hf_damping=50,
       room_scale=100,
       stereo_depth=100,
       pre_delay=20,
       wet_gain=0,
       wet_only=False):

What I made for now is, but it doesn't work, because maybe x[key] have to be converted to str? (but if not i can concatenate )

x = {"reverberance":20,"hf_damping":10}
arr = []
for key in x:
    arr.append(key + "=" + str(x[key]))


reverb(",".join(arr))
whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

2

You can just unpack kwargs directly:

x = {"reverberance":20,"hf_damping":10}

def reverb(
       reverberance=50,
       hf_damping=50,
       room_scale=100,
       stereo_depth=100,
       pre_delay=20,
       wet_gain=0,
       wet_only=False):
    return reverberance, hf_damping

reverb(**x) # returns (20,10)
Julien
  • 13,986
  • 5
  • 29
  • 53