Python: Type error: method receives more arguments than the ones given
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
add a comment |
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
add a comment |
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
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
python-2.7 arguments typeerror
edited Nov 24 '18 at 1:52
Marco Mattia
asked Nov 24 '18 at 1:30
Marco MattiaMarco Mattia
33
33
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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. Thetime
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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. Thetime
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
add a comment |
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.
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. Thetime
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
add a comment |
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.
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.
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. Thetime
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
add a comment |
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. Thetime
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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