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))
1
  • 4
    You can use reverb(**x) Commented Feb 22, 2021 at 6:54

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

** works perfect!! looks like a charm.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.