TypeError: got multiple values for argument












68















I read the other threads that had to do with this error and it seems that my problem has an interesting distinct difference than all the posts I read so far, namely, all the other posts so far have the error in regards to either a user created class or a builtin system resource. I am experiencing this problem when calling a function, I can't figure out what it could be for. Any ideas?



BOX_LENGTH = 100
turtle.speed(0)
fill = 0
for i in range(8):
fill += 1
if fill % 2 == 0:
Horizontol_drawbox(BOX_LENGTH, fillBox = False)
else:
Horizontol_drawbox(BOX_LENGTH, fillBox = True)

for i in range(8):
fill += 1
if fill % 2 == 0:
Vertical_drawbox(BOX_LENGTH,fillBox = False)
else:
Vertical_drawbox(BOX_LENGTH,fillBox = True)


Error message:



    Horizontol_drawbox(BOX_LENGTH, fillBox = True)
TypeError: Horizontol_drawbox() got multiple values for argument 'fillBox'









share|improve this question


















  • 4





    What is the declaration of the Horizontol_drawbox function? If it starts with fillBox, then that's the fault (assigned one time with positional argument, and a second time with keyword argument).

    – Cilyan
    Feb 13 '14 at 20:33
















68















I read the other threads that had to do with this error and it seems that my problem has an interesting distinct difference than all the posts I read so far, namely, all the other posts so far have the error in regards to either a user created class or a builtin system resource. I am experiencing this problem when calling a function, I can't figure out what it could be for. Any ideas?



BOX_LENGTH = 100
turtle.speed(0)
fill = 0
for i in range(8):
fill += 1
if fill % 2 == 0:
Horizontol_drawbox(BOX_LENGTH, fillBox = False)
else:
Horizontol_drawbox(BOX_LENGTH, fillBox = True)

for i in range(8):
fill += 1
if fill % 2 == 0:
Vertical_drawbox(BOX_LENGTH,fillBox = False)
else:
Vertical_drawbox(BOX_LENGTH,fillBox = True)


Error message:



    Horizontol_drawbox(BOX_LENGTH, fillBox = True)
TypeError: Horizontol_drawbox() got multiple values for argument 'fillBox'









share|improve this question


















  • 4





    What is the declaration of the Horizontol_drawbox function? If it starts with fillBox, then that's the fault (assigned one time with positional argument, and a second time with keyword argument).

    – Cilyan
    Feb 13 '14 at 20:33














68












68








68


8






I read the other threads that had to do with this error and it seems that my problem has an interesting distinct difference than all the posts I read so far, namely, all the other posts so far have the error in regards to either a user created class or a builtin system resource. I am experiencing this problem when calling a function, I can't figure out what it could be for. Any ideas?



BOX_LENGTH = 100
turtle.speed(0)
fill = 0
for i in range(8):
fill += 1
if fill % 2 == 0:
Horizontol_drawbox(BOX_LENGTH, fillBox = False)
else:
Horizontol_drawbox(BOX_LENGTH, fillBox = True)

for i in range(8):
fill += 1
if fill % 2 == 0:
Vertical_drawbox(BOX_LENGTH,fillBox = False)
else:
Vertical_drawbox(BOX_LENGTH,fillBox = True)


Error message:



    Horizontol_drawbox(BOX_LENGTH, fillBox = True)
TypeError: Horizontol_drawbox() got multiple values for argument 'fillBox'









share|improve this question














I read the other threads that had to do with this error and it seems that my problem has an interesting distinct difference than all the posts I read so far, namely, all the other posts so far have the error in regards to either a user created class or a builtin system resource. I am experiencing this problem when calling a function, I can't figure out what it could be for. Any ideas?



BOX_LENGTH = 100
turtle.speed(0)
fill = 0
for i in range(8):
fill += 1
if fill % 2 == 0:
Horizontol_drawbox(BOX_LENGTH, fillBox = False)
else:
Horizontol_drawbox(BOX_LENGTH, fillBox = True)

for i in range(8):
fill += 1
if fill % 2 == 0:
Vertical_drawbox(BOX_LENGTH,fillBox = False)
else:
Vertical_drawbox(BOX_LENGTH,fillBox = True)


Error message:



    Horizontol_drawbox(BOX_LENGTH, fillBox = True)
TypeError: Horizontol_drawbox() got multiple values for argument 'fillBox'






python python-3.x






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 13 '14 at 20:26









chopper draw lion4chopper draw lion4

3,281103357




3,281103357








  • 4





    What is the declaration of the Horizontol_drawbox function? If it starts with fillBox, then that's the fault (assigned one time with positional argument, and a second time with keyword argument).

    – Cilyan
    Feb 13 '14 at 20:33














  • 4





    What is the declaration of the Horizontol_drawbox function? If it starts with fillBox, then that's the fault (assigned one time with positional argument, and a second time with keyword argument).

    – Cilyan
    Feb 13 '14 at 20:33








4




4





What is the declaration of the Horizontol_drawbox function? If it starts with fillBox, then that's the fault (assigned one time with positional argument, and a second time with keyword argument).

– Cilyan
Feb 13 '14 at 20:33





What is the declaration of the Horizontol_drawbox function? If it starts with fillBox, then that's the fault (assigned one time with positional argument, and a second time with keyword argument).

– Cilyan
Feb 13 '14 at 20:33












6 Answers
6






active

oldest

votes


















129














This happens when a keyword argument is specified that overwrites a positional argument. For example, let's imagine a function that draws a colored box. The function selects the color to be used and delegates the drawing of the box to another function, relaying all extra arguments.



def color_box(color, *args, **kwargs):
painter.select_color(color)
painter.draw_box(*args, **kwargs)


Then the call



color_box("blellow", color="green", height=20, width=30)


will fail because two values are assigned to color: "blellow" as positional and "green" as keyword. (painter.draw_box is supposed to accept the height and width arguments).



This is easy to see in the example, but of course if one mixes up the arguments at call, it may not be easy to debug:



# misplaced height and width
color_box(20, 30, color="green")


Here, color is assigned 20, then args=[30] and color is again assigned "green".






share|improve this answer


























  • Interesting - when I hit this error, it was also about a color argument. The issue was a bit different - my model_matrix argument became keyword-only, and some legacy code had it passed as a positional argument. The new API was expecting color, and got a 4x4 matrix instead.

    – Tomasz Gandor
    Aug 16 '17 at 19:15











  • Hi, I don't get it for the second example. It also satisfies the condition: When a keyword argument is specified that overwrites a positional argument. But why the latter one can work? What's the rule when python assign the arguments. Thank you.

    – Alston
    Nov 15 '17 at 14:59






  • 1





    @Stallman: the second example I gave is also a non-working one. color=20 conflicts with color="green". The rule for assignment is given right after. More info: docs.python.org/3/tutorial/controlflow.html#keyword-arguments Particularly the 3rd of the 4 "invalid calls" examples.

    – Cilyan
    Nov 17 '17 at 16:58



















38














I had the same problem that is really easy to make, but took me a while to see through.



I had copied the declaration to where I was using it and had left the 'self' argument there, but it took me ages to realise that.



I had



self.myFunction(self, a, b, c='123')


but it should have been



self.myFunction(a, b, c='123')





share|improve this answer
























  • Or replace first self with the class name. ;)

    – Tomasz Gandor
    Aug 16 '17 at 19:16








  • 1





    Did the other way around xD

    – Roelant
    Oct 24 '18 at 11:35



















23














This also happens if you forget selfdeclaration inside class methods.



Example:



class Example():
def is_overlapping(x1, x2, y1, y2):
# Thanks to https://stackoverflow.com/a/12888920/940592
return max(x1, y1) <= min(x2, y2)


Fails calling it like self.is_overlapping(x1=2, x2=4, y1=3, y2=5)
with:




{TypeError} is_overlapping() got multiple values for argument 'x1'




WORKS:



class Example():
def is_overlapping(self, x1, x2, y1, y2):
# Thanks to https://stackoverflow.com/a/12888920/940592
return max(x1, y1) <= min(x2, y2)





share|improve this answer


























  • This comment helps me spot my problem: I forget to add a self argument inside the function declaration. i.e. what should be def myFunction(self, a, b, c='123') was written as def myFunction(a, b, c='123'). And because b takes a list and c takes a scalar, when missing self the arguments messed up and eventually the input of b goes to c, causing the "multiple arguments" error. I make this mistake because I tested this internal method outside the class and forget to add the self back in. Hope helpful for someone else!

    – yuqli
    Feb 4 at 3:15











  • @yuqli This is exactly how I get into this problem as well. ;) Nice to hear that this post helped you.

    – gies0r
    Feb 11 at 9:57



















8














My issue was similar to Q---ten's, but in my case it was that I had forgotten to provide the self argument to a class function:



class A:
def fn(a, b, c=True):
pass


Should become



class A:
def fn(self, a, b, c=True):
pass


This faulty implementation is hard to see when calling the class method as:



a_obj = A()
a.fn(a_val, b_val, c=False)


Which will yield a TypeError: got multiple values for argument. Hopefully, the rest of the answers here are clear enough for anyone to be able to quickly understand and fix the error. If not, hope this answer helps you!






share|improve this answer
























  • I did the same. I wrote a class method that I did not pass self in.

    – Jonathan
    Dec 8 '18 at 19:24



















2














Simply put you can't do the following:



class C(object):
def x(self, y, **kwargs):
# Which y to use, kwargs or declaration?
pass

c = C()
y = "Arbitrary value"
kwargs["y"] = "Arbitrary value"
c.x(y, **kwargs) # FAILS


Because you pass the variable 'y' into the function twice: once as kwargs and once as function declaration.






share|improve this answer

































    1














    I was brought here for a reason not explicitly mentioned in the answers so far, so to save others the trouble:



    The error also occurs if the function arguments have changed order - for the same reason as in the accepted answer: the positional arguments clash with the keyword arguments.



    In my case it was because the argument order of the Pandas set_axis function changed between 0.20 and 0.22:



    0.20: DataFrame.set_axis(axis, labels)
    0.22: DataFrame.set_axis(labels, axis=0, inplace=None)


    Using the commonly found examples for set_axis results in this confusing error, since when you call:



    df.set_axis(['a', 'b', 'c'], axis=1)


    prior to 0.22, ['a', 'b', 'c'] is assigned to axis because it's the first argument, and then the positional argument provides "multiple values".






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21764770%2ftypeerror-got-multiple-values-for-argument%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      129














      This happens when a keyword argument is specified that overwrites a positional argument. For example, let's imagine a function that draws a colored box. The function selects the color to be used and delegates the drawing of the box to another function, relaying all extra arguments.



      def color_box(color, *args, **kwargs):
      painter.select_color(color)
      painter.draw_box(*args, **kwargs)


      Then the call



      color_box("blellow", color="green", height=20, width=30)


      will fail because two values are assigned to color: "blellow" as positional and "green" as keyword. (painter.draw_box is supposed to accept the height and width arguments).



      This is easy to see in the example, but of course if one mixes up the arguments at call, it may not be easy to debug:



      # misplaced height and width
      color_box(20, 30, color="green")


      Here, color is assigned 20, then args=[30] and color is again assigned "green".






      share|improve this answer


























      • Interesting - when I hit this error, it was also about a color argument. The issue was a bit different - my model_matrix argument became keyword-only, and some legacy code had it passed as a positional argument. The new API was expecting color, and got a 4x4 matrix instead.

        – Tomasz Gandor
        Aug 16 '17 at 19:15











      • Hi, I don't get it for the second example. It also satisfies the condition: When a keyword argument is specified that overwrites a positional argument. But why the latter one can work? What's the rule when python assign the arguments. Thank you.

        – Alston
        Nov 15 '17 at 14:59






      • 1





        @Stallman: the second example I gave is also a non-working one. color=20 conflicts with color="green". The rule for assignment is given right after. More info: docs.python.org/3/tutorial/controlflow.html#keyword-arguments Particularly the 3rd of the 4 "invalid calls" examples.

        – Cilyan
        Nov 17 '17 at 16:58
















      129














      This happens when a keyword argument is specified that overwrites a positional argument. For example, let's imagine a function that draws a colored box. The function selects the color to be used and delegates the drawing of the box to another function, relaying all extra arguments.



      def color_box(color, *args, **kwargs):
      painter.select_color(color)
      painter.draw_box(*args, **kwargs)


      Then the call



      color_box("blellow", color="green", height=20, width=30)


      will fail because two values are assigned to color: "blellow" as positional and "green" as keyword. (painter.draw_box is supposed to accept the height and width arguments).



      This is easy to see in the example, but of course if one mixes up the arguments at call, it may not be easy to debug:



      # misplaced height and width
      color_box(20, 30, color="green")


      Here, color is assigned 20, then args=[30] and color is again assigned "green".






      share|improve this answer


























      • Interesting - when I hit this error, it was also about a color argument. The issue was a bit different - my model_matrix argument became keyword-only, and some legacy code had it passed as a positional argument. The new API was expecting color, and got a 4x4 matrix instead.

        – Tomasz Gandor
        Aug 16 '17 at 19:15











      • Hi, I don't get it for the second example. It also satisfies the condition: When a keyword argument is specified that overwrites a positional argument. But why the latter one can work? What's the rule when python assign the arguments. Thank you.

        – Alston
        Nov 15 '17 at 14:59






      • 1





        @Stallman: the second example I gave is also a non-working one. color=20 conflicts with color="green". The rule for assignment is given right after. More info: docs.python.org/3/tutorial/controlflow.html#keyword-arguments Particularly the 3rd of the 4 "invalid calls" examples.

        – Cilyan
        Nov 17 '17 at 16:58














      129












      129








      129







      This happens when a keyword argument is specified that overwrites a positional argument. For example, let's imagine a function that draws a colored box. The function selects the color to be used and delegates the drawing of the box to another function, relaying all extra arguments.



      def color_box(color, *args, **kwargs):
      painter.select_color(color)
      painter.draw_box(*args, **kwargs)


      Then the call



      color_box("blellow", color="green", height=20, width=30)


      will fail because two values are assigned to color: "blellow" as positional and "green" as keyword. (painter.draw_box is supposed to accept the height and width arguments).



      This is easy to see in the example, but of course if one mixes up the arguments at call, it may not be easy to debug:



      # misplaced height and width
      color_box(20, 30, color="green")


      Here, color is assigned 20, then args=[30] and color is again assigned "green".






      share|improve this answer















      This happens when a keyword argument is specified that overwrites a positional argument. For example, let's imagine a function that draws a colored box. The function selects the color to be used and delegates the drawing of the box to another function, relaying all extra arguments.



      def color_box(color, *args, **kwargs):
      painter.select_color(color)
      painter.draw_box(*args, **kwargs)


      Then the call



      color_box("blellow", color="green", height=20, width=30)


      will fail because two values are assigned to color: "blellow" as positional and "green" as keyword. (painter.draw_box is supposed to accept the height and width arguments).



      This is easy to see in the example, but of course if one mixes up the arguments at call, it may not be easy to debug:



      # misplaced height and width
      color_box(20, 30, color="green")


      Here, color is assigned 20, then args=[30] and color is again assigned "green".







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 31 '16 at 5:51









      arogachev

      28k582102




      28k582102










      answered Feb 13 '14 at 20:54









      CilyanCilyan

      3,85011930




      3,85011930













      • Interesting - when I hit this error, it was also about a color argument. The issue was a bit different - my model_matrix argument became keyword-only, and some legacy code had it passed as a positional argument. The new API was expecting color, and got a 4x4 matrix instead.

        – Tomasz Gandor
        Aug 16 '17 at 19:15











      • Hi, I don't get it for the second example. It also satisfies the condition: When a keyword argument is specified that overwrites a positional argument. But why the latter one can work? What's the rule when python assign the arguments. Thank you.

        – Alston
        Nov 15 '17 at 14:59






      • 1





        @Stallman: the second example I gave is also a non-working one. color=20 conflicts with color="green". The rule for assignment is given right after. More info: docs.python.org/3/tutorial/controlflow.html#keyword-arguments Particularly the 3rd of the 4 "invalid calls" examples.

        – Cilyan
        Nov 17 '17 at 16:58



















      • Interesting - when I hit this error, it was also about a color argument. The issue was a bit different - my model_matrix argument became keyword-only, and some legacy code had it passed as a positional argument. The new API was expecting color, and got a 4x4 matrix instead.

        – Tomasz Gandor
        Aug 16 '17 at 19:15











      • Hi, I don't get it for the second example. It also satisfies the condition: When a keyword argument is specified that overwrites a positional argument. But why the latter one can work? What's the rule when python assign the arguments. Thank you.

        – Alston
        Nov 15 '17 at 14:59






      • 1





        @Stallman: the second example I gave is also a non-working one. color=20 conflicts with color="green". The rule for assignment is given right after. More info: docs.python.org/3/tutorial/controlflow.html#keyword-arguments Particularly the 3rd of the 4 "invalid calls" examples.

        – Cilyan
        Nov 17 '17 at 16:58

















      Interesting - when I hit this error, it was also about a color argument. The issue was a bit different - my model_matrix argument became keyword-only, and some legacy code had it passed as a positional argument. The new API was expecting color, and got a 4x4 matrix instead.

      – Tomasz Gandor
      Aug 16 '17 at 19:15





      Interesting - when I hit this error, it was also about a color argument. The issue was a bit different - my model_matrix argument became keyword-only, and some legacy code had it passed as a positional argument. The new API was expecting color, and got a 4x4 matrix instead.

      – Tomasz Gandor
      Aug 16 '17 at 19:15













      Hi, I don't get it for the second example. It also satisfies the condition: When a keyword argument is specified that overwrites a positional argument. But why the latter one can work? What's the rule when python assign the arguments. Thank you.

      – Alston
      Nov 15 '17 at 14:59





      Hi, I don't get it for the second example. It also satisfies the condition: When a keyword argument is specified that overwrites a positional argument. But why the latter one can work? What's the rule when python assign the arguments. Thank you.

      – Alston
      Nov 15 '17 at 14:59




      1




      1





      @Stallman: the second example I gave is also a non-working one. color=20 conflicts with color="green". The rule for assignment is given right after. More info: docs.python.org/3/tutorial/controlflow.html#keyword-arguments Particularly the 3rd of the 4 "invalid calls" examples.

      – Cilyan
      Nov 17 '17 at 16:58





      @Stallman: the second example I gave is also a non-working one. color=20 conflicts with color="green". The rule for assignment is given right after. More info: docs.python.org/3/tutorial/controlflow.html#keyword-arguments Particularly the 3rd of the 4 "invalid calls" examples.

      – Cilyan
      Nov 17 '17 at 16:58













      38














      I had the same problem that is really easy to make, but took me a while to see through.



      I had copied the declaration to where I was using it and had left the 'self' argument there, but it took me ages to realise that.



      I had



      self.myFunction(self, a, b, c='123')


      but it should have been



      self.myFunction(a, b, c='123')





      share|improve this answer
























      • Or replace first self with the class name. ;)

        – Tomasz Gandor
        Aug 16 '17 at 19:16








      • 1





        Did the other way around xD

        – Roelant
        Oct 24 '18 at 11:35
















      38














      I had the same problem that is really easy to make, but took me a while to see through.



      I had copied the declaration to where I was using it and had left the 'self' argument there, but it took me ages to realise that.



      I had



      self.myFunction(self, a, b, c='123')


      but it should have been



      self.myFunction(a, b, c='123')





      share|improve this answer
























      • Or replace first self with the class name. ;)

        – Tomasz Gandor
        Aug 16 '17 at 19:16








      • 1





        Did the other way around xD

        – Roelant
        Oct 24 '18 at 11:35














      38












      38








      38







      I had the same problem that is really easy to make, but took me a while to see through.



      I had copied the declaration to where I was using it and had left the 'self' argument there, but it took me ages to realise that.



      I had



      self.myFunction(self, a, b, c='123')


      but it should have been



      self.myFunction(a, b, c='123')





      share|improve this answer













      I had the same problem that is really easy to make, but took me a while to see through.



      I had copied the declaration to where I was using it and had left the 'self' argument there, but it took me ages to realise that.



      I had



      self.myFunction(self, a, b, c='123')


      but it should have been



      self.myFunction(a, b, c='123')






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 6 '15 at 5:09









      Q---tenQ---ten

      62669




      62669













      • Or replace first self with the class name. ;)

        – Tomasz Gandor
        Aug 16 '17 at 19:16








      • 1





        Did the other way around xD

        – Roelant
        Oct 24 '18 at 11:35



















      • Or replace first self with the class name. ;)

        – Tomasz Gandor
        Aug 16 '17 at 19:16








      • 1





        Did the other way around xD

        – Roelant
        Oct 24 '18 at 11:35

















      Or replace first self with the class name. ;)

      – Tomasz Gandor
      Aug 16 '17 at 19:16







      Or replace first self with the class name. ;)

      – Tomasz Gandor
      Aug 16 '17 at 19:16






      1




      1





      Did the other way around xD

      – Roelant
      Oct 24 '18 at 11:35





      Did the other way around xD

      – Roelant
      Oct 24 '18 at 11:35











      23














      This also happens if you forget selfdeclaration inside class methods.



      Example:



      class Example():
      def is_overlapping(x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)


      Fails calling it like self.is_overlapping(x1=2, x2=4, y1=3, y2=5)
      with:




      {TypeError} is_overlapping() got multiple values for argument 'x1'




      WORKS:



      class Example():
      def is_overlapping(self, x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)





      share|improve this answer


























      • This comment helps me spot my problem: I forget to add a self argument inside the function declaration. i.e. what should be def myFunction(self, a, b, c='123') was written as def myFunction(a, b, c='123'). And because b takes a list and c takes a scalar, when missing self the arguments messed up and eventually the input of b goes to c, causing the "multiple arguments" error. I make this mistake because I tested this internal method outside the class and forget to add the self back in. Hope helpful for someone else!

        – yuqli
        Feb 4 at 3:15











      • @yuqli This is exactly how I get into this problem as well. ;) Nice to hear that this post helped you.

        – gies0r
        Feb 11 at 9:57
















      23














      This also happens if you forget selfdeclaration inside class methods.



      Example:



      class Example():
      def is_overlapping(x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)


      Fails calling it like self.is_overlapping(x1=2, x2=4, y1=3, y2=5)
      with:




      {TypeError} is_overlapping() got multiple values for argument 'x1'




      WORKS:



      class Example():
      def is_overlapping(self, x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)





      share|improve this answer


























      • This comment helps me spot my problem: I forget to add a self argument inside the function declaration. i.e. what should be def myFunction(self, a, b, c='123') was written as def myFunction(a, b, c='123'). And because b takes a list and c takes a scalar, when missing self the arguments messed up and eventually the input of b goes to c, causing the "multiple arguments" error. I make this mistake because I tested this internal method outside the class and forget to add the self back in. Hope helpful for someone else!

        – yuqli
        Feb 4 at 3:15











      • @yuqli This is exactly how I get into this problem as well. ;) Nice to hear that this post helped you.

        – gies0r
        Feb 11 at 9:57














      23












      23








      23







      This also happens if you forget selfdeclaration inside class methods.



      Example:



      class Example():
      def is_overlapping(x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)


      Fails calling it like self.is_overlapping(x1=2, x2=4, y1=3, y2=5)
      with:




      {TypeError} is_overlapping() got multiple values for argument 'x1'




      WORKS:



      class Example():
      def is_overlapping(self, x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)





      share|improve this answer















      This also happens if you forget selfdeclaration inside class methods.



      Example:



      class Example():
      def is_overlapping(x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)


      Fails calling it like self.is_overlapping(x1=2, x2=4, y1=3, y2=5)
      with:




      {TypeError} is_overlapping() got multiple values for argument 'x1'




      WORKS:



      class Example():
      def is_overlapping(self, x1, x2, y1, y2):
      # Thanks to https://stackoverflow.com/a/12888920/940592
      return max(x1, y1) <= min(x2, y2)






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 19 '17 at 3:08









      Kir Chou

      1,79412031




      1,79412031










      answered Jun 26 '17 at 16:17









      gies0rgies0r

      7771118




      7771118













      • This comment helps me spot my problem: I forget to add a self argument inside the function declaration. i.e. what should be def myFunction(self, a, b, c='123') was written as def myFunction(a, b, c='123'). And because b takes a list and c takes a scalar, when missing self the arguments messed up and eventually the input of b goes to c, causing the "multiple arguments" error. I make this mistake because I tested this internal method outside the class and forget to add the self back in. Hope helpful for someone else!

        – yuqli
        Feb 4 at 3:15











      • @yuqli This is exactly how I get into this problem as well. ;) Nice to hear that this post helped you.

        – gies0r
        Feb 11 at 9:57



















      • This comment helps me spot my problem: I forget to add a self argument inside the function declaration. i.e. what should be def myFunction(self, a, b, c='123') was written as def myFunction(a, b, c='123'). And because b takes a list and c takes a scalar, when missing self the arguments messed up and eventually the input of b goes to c, causing the "multiple arguments" error. I make this mistake because I tested this internal method outside the class and forget to add the self back in. Hope helpful for someone else!

        – yuqli
        Feb 4 at 3:15











      • @yuqli This is exactly how I get into this problem as well. ;) Nice to hear that this post helped you.

        – gies0r
        Feb 11 at 9:57

















      This comment helps me spot my problem: I forget to add a self argument inside the function declaration. i.e. what should be def myFunction(self, a, b, c='123') was written as def myFunction(a, b, c='123'). And because b takes a list and c takes a scalar, when missing self the arguments messed up and eventually the input of b goes to c, causing the "multiple arguments" error. I make this mistake because I tested this internal method outside the class and forget to add the self back in. Hope helpful for someone else!

      – yuqli
      Feb 4 at 3:15





      This comment helps me spot my problem: I forget to add a self argument inside the function declaration. i.e. what should be def myFunction(self, a, b, c='123') was written as def myFunction(a, b, c='123'). And because b takes a list and c takes a scalar, when missing self the arguments messed up and eventually the input of b goes to c, causing the "multiple arguments" error. I make this mistake because I tested this internal method outside the class and forget to add the self back in. Hope helpful for someone else!

      – yuqli
      Feb 4 at 3:15













      @yuqli This is exactly how I get into this problem as well. ;) Nice to hear that this post helped you.

      – gies0r
      Feb 11 at 9:57





      @yuqli This is exactly how I get into this problem as well. ;) Nice to hear that this post helped you.

      – gies0r
      Feb 11 at 9:57











      8














      My issue was similar to Q---ten's, but in my case it was that I had forgotten to provide the self argument to a class function:



      class A:
      def fn(a, b, c=True):
      pass


      Should become



      class A:
      def fn(self, a, b, c=True):
      pass


      This faulty implementation is hard to see when calling the class method as:



      a_obj = A()
      a.fn(a_val, b_val, c=False)


      Which will yield a TypeError: got multiple values for argument. Hopefully, the rest of the answers here are clear enough for anyone to be able to quickly understand and fix the error. If not, hope this answer helps you!






      share|improve this answer
























      • I did the same. I wrote a class method that I did not pass self in.

        – Jonathan
        Dec 8 '18 at 19:24
















      8














      My issue was similar to Q---ten's, but in my case it was that I had forgotten to provide the self argument to a class function:



      class A:
      def fn(a, b, c=True):
      pass


      Should become



      class A:
      def fn(self, a, b, c=True):
      pass


      This faulty implementation is hard to see when calling the class method as:



      a_obj = A()
      a.fn(a_val, b_val, c=False)


      Which will yield a TypeError: got multiple values for argument. Hopefully, the rest of the answers here are clear enough for anyone to be able to quickly understand and fix the error. If not, hope this answer helps you!






      share|improve this answer
























      • I did the same. I wrote a class method that I did not pass self in.

        – Jonathan
        Dec 8 '18 at 19:24














      8












      8








      8







      My issue was similar to Q---ten's, but in my case it was that I had forgotten to provide the self argument to a class function:



      class A:
      def fn(a, b, c=True):
      pass


      Should become



      class A:
      def fn(self, a, b, c=True):
      pass


      This faulty implementation is hard to see when calling the class method as:



      a_obj = A()
      a.fn(a_val, b_val, c=False)


      Which will yield a TypeError: got multiple values for argument. Hopefully, the rest of the answers here are clear enough for anyone to be able to quickly understand and fix the error. If not, hope this answer helps you!






      share|improve this answer













      My issue was similar to Q---ten's, but in my case it was that I had forgotten to provide the self argument to a class function:



      class A:
      def fn(a, b, c=True):
      pass


      Should become



      class A:
      def fn(self, a, b, c=True):
      pass


      This faulty implementation is hard to see when calling the class method as:



      a_obj = A()
      a.fn(a_val, b_val, c=False)


      Which will yield a TypeError: got multiple values for argument. Hopefully, the rest of the answers here are clear enough for anyone to be able to quickly understand and fix the error. If not, hope this answer helps you!







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jun 14 '18 at 10:03









      Andreas ForslöwAndreas Forslöw

      260311




      260311













      • I did the same. I wrote a class method that I did not pass self in.

        – Jonathan
        Dec 8 '18 at 19:24



















      • I did the same. I wrote a class method that I did not pass self in.

        – Jonathan
        Dec 8 '18 at 19:24

















      I did the same. I wrote a class method that I did not pass self in.

      – Jonathan
      Dec 8 '18 at 19:24





      I did the same. I wrote a class method that I did not pass self in.

      – Jonathan
      Dec 8 '18 at 19:24











      2














      Simply put you can't do the following:



      class C(object):
      def x(self, y, **kwargs):
      # Which y to use, kwargs or declaration?
      pass

      c = C()
      y = "Arbitrary value"
      kwargs["y"] = "Arbitrary value"
      c.x(y, **kwargs) # FAILS


      Because you pass the variable 'y' into the function twice: once as kwargs and once as function declaration.






      share|improve this answer






























        2














        Simply put you can't do the following:



        class C(object):
        def x(self, y, **kwargs):
        # Which y to use, kwargs or declaration?
        pass

        c = C()
        y = "Arbitrary value"
        kwargs["y"] = "Arbitrary value"
        c.x(y, **kwargs) # FAILS


        Because you pass the variable 'y' into the function twice: once as kwargs and once as function declaration.






        share|improve this answer




























          2












          2








          2







          Simply put you can't do the following:



          class C(object):
          def x(self, y, **kwargs):
          # Which y to use, kwargs or declaration?
          pass

          c = C()
          y = "Arbitrary value"
          kwargs["y"] = "Arbitrary value"
          c.x(y, **kwargs) # FAILS


          Because you pass the variable 'y' into the function twice: once as kwargs and once as function declaration.






          share|improve this answer















          Simply put you can't do the following:



          class C(object):
          def x(self, y, **kwargs):
          # Which y to use, kwargs or declaration?
          pass

          c = C()
          y = "Arbitrary value"
          kwargs["y"] = "Arbitrary value"
          c.x(y, **kwargs) # FAILS


          Because you pass the variable 'y' into the function twice: once as kwargs and once as function declaration.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 17 '17 at 12:24

























          answered May 31 '17 at 23:50









          quasipolynomialquasipolynomial

          697




          697























              1














              I was brought here for a reason not explicitly mentioned in the answers so far, so to save others the trouble:



              The error also occurs if the function arguments have changed order - for the same reason as in the accepted answer: the positional arguments clash with the keyword arguments.



              In my case it was because the argument order of the Pandas set_axis function changed between 0.20 and 0.22:



              0.20: DataFrame.set_axis(axis, labels)
              0.22: DataFrame.set_axis(labels, axis=0, inplace=None)


              Using the commonly found examples for set_axis results in this confusing error, since when you call:



              df.set_axis(['a', 'b', 'c'], axis=1)


              prior to 0.22, ['a', 'b', 'c'] is assigned to axis because it's the first argument, and then the positional argument provides "multiple values".






              share|improve this answer




























                1














                I was brought here for a reason not explicitly mentioned in the answers so far, so to save others the trouble:



                The error also occurs if the function arguments have changed order - for the same reason as in the accepted answer: the positional arguments clash with the keyword arguments.



                In my case it was because the argument order of the Pandas set_axis function changed between 0.20 and 0.22:



                0.20: DataFrame.set_axis(axis, labels)
                0.22: DataFrame.set_axis(labels, axis=0, inplace=None)


                Using the commonly found examples for set_axis results in this confusing error, since when you call:



                df.set_axis(['a', 'b', 'c'], axis=1)


                prior to 0.22, ['a', 'b', 'c'] is assigned to axis because it's the first argument, and then the positional argument provides "multiple values".






                share|improve this answer


























                  1












                  1








                  1







                  I was brought here for a reason not explicitly mentioned in the answers so far, so to save others the trouble:



                  The error also occurs if the function arguments have changed order - for the same reason as in the accepted answer: the positional arguments clash with the keyword arguments.



                  In my case it was because the argument order of the Pandas set_axis function changed between 0.20 and 0.22:



                  0.20: DataFrame.set_axis(axis, labels)
                  0.22: DataFrame.set_axis(labels, axis=0, inplace=None)


                  Using the commonly found examples for set_axis results in this confusing error, since when you call:



                  df.set_axis(['a', 'b', 'c'], axis=1)


                  prior to 0.22, ['a', 'b', 'c'] is assigned to axis because it's the first argument, and then the positional argument provides "multiple values".






                  share|improve this answer













                  I was brought here for a reason not explicitly mentioned in the answers so far, so to save others the trouble:



                  The error also occurs if the function arguments have changed order - for the same reason as in the accepted answer: the positional arguments clash with the keyword arguments.



                  In my case it was because the argument order of the Pandas set_axis function changed between 0.20 and 0.22:



                  0.20: DataFrame.set_axis(axis, labels)
                  0.22: DataFrame.set_axis(labels, axis=0, inplace=None)


                  Using the commonly found examples for set_axis results in this confusing error, since when you call:



                  df.set_axis(['a', 'b', 'c'], axis=1)


                  prior to 0.22, ['a', 'b', 'c'] is assigned to axis because it's the first argument, and then the positional argument provides "multiple values".







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 4 '18 at 16:29









                  Heath RafteryHeath Raftery

                  1,407615




                  1,407615






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21764770%2ftypeerror-got-multiple-values-for-argument%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Academy of Television Arts & Sciences

                      L'Équipe

                      1995 France bombings