Python: Type error: method receives more arguments than the ones given












0















I have created this class to determine the normalisation function of a distribution.
Here is the class with relative main:



class Normaliser(object):

def funcN(f, xIni, xFin, yIni, yFin):

return sym.integrate(f, (x, xIni,
xFin), (y, yIni, yFin))


def main():
f = (1+sym.cos(x)**2)*sym.exp(-y/t)
g = (3*sym.sin(x)**2)*sym.exp(-y/t)
xIni = 0.
xFin = 2*pi
yIni = 0.
yFin = 10.
tau1 = 1.
tau2 = 2.
*funcN1 = Normaliser().funcN(f, xIni,
xFin, yIni, yFin)*
*funcN2 = Normaliser().funcN(g, xIni,
xFin, yIni, yFin)*


When I run the tester I get the following error in the emphasised lines:



TypeError: funcN() takes exactly 5 
arguments (6 given)


I really don't understand where this error is arising from considering that there is no self in the method. If anybody has any idea of a possible reason and possibly for a solution as well, I would be very grateful. Thanks in advance!










share|improve this question





























    0















    I have created this class to determine the normalisation function of a distribution.
    Here is the class with relative main:



    class Normaliser(object):

    def funcN(f, xIni, xFin, yIni, yFin):

    return sym.integrate(f, (x, xIni,
    xFin), (y, yIni, yFin))


    def main():
    f = (1+sym.cos(x)**2)*sym.exp(-y/t)
    g = (3*sym.sin(x)**2)*sym.exp(-y/t)
    xIni = 0.
    xFin = 2*pi
    yIni = 0.
    yFin = 10.
    tau1 = 1.
    tau2 = 2.
    *funcN1 = Normaliser().funcN(f, xIni,
    xFin, yIni, yFin)*
    *funcN2 = Normaliser().funcN(g, xIni,
    xFin, yIni, yFin)*


    When I run the tester I get the following error in the emphasised lines:



    TypeError: funcN() takes exactly 5 
    arguments (6 given)


    I really don't understand where this error is arising from considering that there is no self in the method. If anybody has any idea of a possible reason and possibly for a solution as well, I would be very grateful. Thanks in advance!










    share|improve this question



























      0












      0








      0








      I have created this class to determine the normalisation function of a distribution.
      Here is the class with relative main:



      class Normaliser(object):

      def funcN(f, xIni, xFin, yIni, yFin):

      return sym.integrate(f, (x, xIni,
      xFin), (y, yIni, yFin))


      def main():
      f = (1+sym.cos(x)**2)*sym.exp(-y/t)
      g = (3*sym.sin(x)**2)*sym.exp(-y/t)
      xIni = 0.
      xFin = 2*pi
      yIni = 0.
      yFin = 10.
      tau1 = 1.
      tau2 = 2.
      *funcN1 = Normaliser().funcN(f, xIni,
      xFin, yIni, yFin)*
      *funcN2 = Normaliser().funcN(g, xIni,
      xFin, yIni, yFin)*


      When I run the tester I get the following error in the emphasised lines:



      TypeError: funcN() takes exactly 5 
      arguments (6 given)


      I really don't understand where this error is arising from considering that there is no self in the method. If anybody has any idea of a possible reason and possibly for a solution as well, I would be very grateful. Thanks in advance!










      share|improve this question
















      I have created this class to determine the normalisation function of a distribution.
      Here is the class with relative main:



      class Normaliser(object):

      def funcN(f, xIni, xFin, yIni, yFin):

      return sym.integrate(f, (x, xIni,
      xFin), (y, yIni, yFin))


      def main():
      f = (1+sym.cos(x)**2)*sym.exp(-y/t)
      g = (3*sym.sin(x)**2)*sym.exp(-y/t)
      xIni = 0.
      xFin = 2*pi
      yIni = 0.
      yFin = 10.
      tau1 = 1.
      tau2 = 2.
      *funcN1 = Normaliser().funcN(f, xIni,
      xFin, yIni, yFin)*
      *funcN2 = Normaliser().funcN(g, xIni,
      xFin, yIni, yFin)*


      When I run the tester I get the following error in the emphasised lines:



      TypeError: funcN() takes exactly 5 
      arguments (6 given)


      I really don't understand where this error is arising from considering that there is no self in the method. If anybody has any idea of a possible reason and possibly for a solution as well, I would be very grateful. Thanks in advance!







      python-2.7 arguments typeerror






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 1:52







      Marco Mattia

















      asked Nov 24 '18 at 1:30









      Marco MattiaMarco Mattia

      33




      33
























          1 Answer
          1






          active

          oldest

          votes


















          0














          As regular member function of the Normaliser class, funcN is passed the Normaliser object it is being invoked on (canonically named self) as the first parameter. This implicit parameter is added before any explicit parameters.

          Since you defined the function to take five parameters and passed five explicit parameters, the function is called with six parameters - one implicit, and five explicit.

          If funcN doesn't use any (instance or class) member variables of Normaliser, it could be defined outside any class or marked with the @staticmethod decorator to avoid the implicit self being added.






          share|improve this answer
























          • Ok thank you very much! I understand it much better now! However another doubt arises now, do you think it is ok to make a class only with static methods or is it malpractice?

            – Marco Mattia
            Nov 24 '18 at 14:33











          • If they have something in common (e.g., they all work on the same data structure or are steps in a process) I don't see any problem, especially if there are only a few methods. I think it's more conventional to use a module for this kind of grouping; invocation of a staticmethods and a module-level function is the same. The time module is an example of a module like this (although it is implemented in C, so it's not a perfect example).

            – cco
            Nov 25 '18 at 1:21











          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%2f53454429%2fpython-type-error-method-receives-more-arguments-than-the-ones-given%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          As regular member function of the Normaliser class, funcN is passed the Normaliser object it is being invoked on (canonically named self) as the first parameter. This implicit parameter is added before any explicit parameters.

          Since you defined the function to take five parameters and passed five explicit parameters, the function is called with six parameters - one implicit, and five explicit.

          If funcN doesn't use any (instance or class) member variables of Normaliser, it could be defined outside any class or marked with the @staticmethod decorator to avoid the implicit self being added.






          share|improve this answer
























          • Ok thank you very much! I understand it much better now! However another doubt arises now, do you think it is ok to make a class only with static methods or is it malpractice?

            – Marco Mattia
            Nov 24 '18 at 14:33











          • If they have something in common (e.g., they all work on the same data structure or are steps in a process) I don't see any problem, especially if there are only a few methods. I think it's more conventional to use a module for this kind of grouping; invocation of a staticmethods and a module-level function is the same. The time module is an example of a module like this (although it is implemented in C, so it's not a perfect example).

            – cco
            Nov 25 '18 at 1:21
















          0














          As regular member function of the Normaliser class, funcN is passed the Normaliser object it is being invoked on (canonically named self) as the first parameter. This implicit parameter is added before any explicit parameters.

          Since you defined the function to take five parameters and passed five explicit parameters, the function is called with six parameters - one implicit, and five explicit.

          If funcN doesn't use any (instance or class) member variables of Normaliser, it could be defined outside any class or marked with the @staticmethod decorator to avoid the implicit self being added.






          share|improve this answer
























          • Ok thank you very much! I understand it much better now! However another doubt arises now, do you think it is ok to make a class only with static methods or is it malpractice?

            – Marco Mattia
            Nov 24 '18 at 14:33











          • If they have something in common (e.g., they all work on the same data structure or are steps in a process) I don't see any problem, especially if there are only a few methods. I think it's more conventional to use a module for this kind of grouping; invocation of a staticmethods and a module-level function is the same. The time module is an example of a module like this (although it is implemented in C, so it's not a perfect example).

            – cco
            Nov 25 '18 at 1:21














          0












          0








          0







          As regular member function of the Normaliser class, funcN is passed the Normaliser object it is being invoked on (canonically named self) as the first parameter. This implicit parameter is added before any explicit parameters.

          Since you defined the function to take five parameters and passed five explicit parameters, the function is called with six parameters - one implicit, and five explicit.

          If funcN doesn't use any (instance or class) member variables of Normaliser, it could be defined outside any class or marked with the @staticmethod decorator to avoid the implicit self being added.






          share|improve this answer













          As regular member function of the Normaliser class, funcN is passed the Normaliser object it is being invoked on (canonically named self) as the first parameter. This implicit parameter is added before any explicit parameters.

          Since you defined the function to take five parameters and passed five explicit parameters, the function is called with six parameters - one implicit, and five explicit.

          If funcN doesn't use any (instance or class) member variables of Normaliser, it could be defined outside any class or marked with the @staticmethod decorator to avoid the implicit self being added.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 11:57









          ccocco

          3,5641817




          3,5641817













          • Ok thank you very much! I understand it much better now! However another doubt arises now, do you think it is ok to make a class only with static methods or is it malpractice?

            – Marco Mattia
            Nov 24 '18 at 14:33











          • If they have something in common (e.g., they all work on the same data structure or are steps in a process) I don't see any problem, especially if there are only a few methods. I think it's more conventional to use a module for this kind of grouping; invocation of a staticmethods and a module-level function is the same. The time module is an example of a module like this (although it is implemented in C, so it's not a perfect example).

            – cco
            Nov 25 '18 at 1:21



















          • Ok thank you very much! I understand it much better now! However another doubt arises now, do you think it is ok to make a class only with static methods or is it malpractice?

            – Marco Mattia
            Nov 24 '18 at 14:33











          • If they have something in common (e.g., they all work on the same data structure or are steps in a process) I don't see any problem, especially if there are only a few methods. I think it's more conventional to use a module for this kind of grouping; invocation of a staticmethods and a module-level function is the same. The time module is an example of a module like this (although it is implemented in C, so it's not a perfect example).

            – cco
            Nov 25 '18 at 1:21

















          Ok thank you very much! I understand it much better now! However another doubt arises now, do you think it is ok to make a class only with static methods or is it malpractice?

          – Marco Mattia
          Nov 24 '18 at 14:33





          Ok thank you very much! I understand it much better now! However another doubt arises now, do you think it is ok to make a class only with static methods or is it malpractice?

          – Marco Mattia
          Nov 24 '18 at 14:33













          If they have something in common (e.g., they all work on the same data structure or are steps in a process) I don't see any problem, especially if there are only a few methods. I think it's more conventional to use a module for this kind of grouping; invocation of a staticmethods and a module-level function is the same. The time module is an example of a module like this (although it is implemented in C, so it's not a perfect example).

          – cco
          Nov 25 '18 at 1:21





          If they have something in common (e.g., they all work on the same data structure or are steps in a process) I don't see any problem, especially if there are only a few methods. I think it's more conventional to use a module for this kind of grouping; invocation of a staticmethods and a module-level function is the same. The time module is an example of a module like this (although it is implemented in C, so it's not a perfect example).

          – cco
          Nov 25 '18 at 1:21


















          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%2f53454429%2fpython-type-error-method-receives-more-arguments-than-the-ones-given%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







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks