0

Im trying to create a function that takes 6 arguments, 3 of which are "optional" given that I tried giving them default values. This function takes in the 6 values and gives them to another function (defined previously).

Every time I try to run it I get a TypeError: Coeff() got an unexpected keyword argument 'h'. I was hoping someone could help me with this!

def TSR_inf(coeff, maxmin, d, h='houle', t_h=0, Per=0):

   coeff = coeff
   maxmin = maxmin
   d=d
   h = h
   t_h = t_h
   Per = Per

   Coeff(coeff, maxmin, d, h='houle', t_h=0, Per=0)

The Coeff() function is defined as such:

def Coeff(coeff, maxmin, d, h='houle', t_h=0, Per=0):

  if coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 0 and Per == 0 and h == 'houle':
      Wave_max('x')
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 0 and Per == 0 and h == 'no houle':
      Wave_max('x', 'no houle')
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'reg' and Per == 0 and h == 'houle':
      Wave_max('x', 'reg')
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'reg' and Per == 1 and h == 'houle':
      Wave_max('x', 'reg', 1)
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'reg' and Per == 1.5 and h == 'houle':
      Wave_max('x', 'reg', 1.5)
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'reg' and Per == 2 and h == 'houle':
      Wave_max('x', 'reg', 2)
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'irreg' and Per == 0 and h == 'houle':
      Wave_max('x', 'reg')
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'irreg' and Per == 1 and h == 'houle':
      Wave_max('x', 'reg', 1)
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'irreg' and Per == 1.5 and h == 'houle':
      Wave_max('x', 'reg', 1.5)
  elif coeff == 'wave' and maxmin == 'max' and d == 'x' and t_h == 'irreg' and Per == 2 and h == 'houle':
      Wave_max('x', 'reg', 2)

This Coeff() function calls another function def Wave_max(d, h, t_h, Per): that I won't post here because it is irrelevant (but if you do want it let me know and I'll add it later).

If anyone can spot where I made the mistake that leads to the TypeError I won't be veery much appreciated!!

Cheers all! (and thank you in advance!)

4
  • Are you saying that even with the edited version of the code (in which 'h1' appears nowhere), you get an error message referencing 'h1'? Commented Jul 7, 2022 at 9:52
  • nooo! I forgot to take that h1 too ahah! Its already gone! Commented Jul 7, 2022 at 9:53
  • Thanks - I can't replicate the issue with the code you have. The problem may lie outside of what you posted: for example, do you have a different Coeff function in another module, and you've imported that instead of the one you show? Commented Jul 7, 2022 at 9:58
  • I dont have any other! I imported this Coeff function from another module, and thats it (other than pandas, numpy, etc etc)! I think that I might just Copy-Paste the function to my script! I was just trying to avoid it because my script is now too long and since I need to present the main script, I wanted to keep it under 1500 lines! Commented Jul 7, 2022 at 10:06

2 Answers 2

0

It's happening because the parameter name is h in the Coeff function and there is no parameter called h1 as the error rightly points out.

You probably want to do something like Coeff(coeff1, maxmin1, d1, h=h1, t_h=t_h1, Per=Per1) at the end of the TSR_inf function.

Sign up to request clarification or add additional context in comments.

1 Comment

That name was just a way to pin point the location of the error! I had it just with h, and the error persists!
0

when you pass an keyword argument always use the same argument name as used in the function definition, the issue is your function argument are h='houle', t_h=0, Per=0 and you are calling the function with h1='houle', t_h1=0, Per1=0

your actual function call should be:

Coeff(coeff1, maxmin1, d1, h='houle', t_h=0, Per=0)

or as you have already stroed them in variables

Coeff(coeff1, maxmin1, d1, h=h1, t_h=t_h1, Per=Per1)

and if you want to use h1 as keyword argument in Coeff function you can change your function definition as

 def  Coeff(coeff1, maxmin1, d1, h='houle', t_h=0, Per=0, **kwargs)

and use h1 in the function as

kwargs.get('h1')

3 Comments

I edited the post to show how my code is now (I only used, for example, h1 to try to pinpoint the location where the Error occurred)!
I tried to run the code, it is working fine, your issue might be causing by some thing else
yeah possibly! Revision time now ahaha! thank you still!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.