Takes Exactly 2 Arguments (1 Given) When Including Self
Everytime I call my function def hello(self,value) I get an error : takes exactly 2 arguments (1 given) so what could I do ? Or is there another possibility to do this: self.statu
Solution 1:
It sounds like you aren't calling your hello function correctly. Given the following class definition:
classWidget(object):
defhello(self, value):
print("hello: " + str(value))
You are probably calling it like a static function like this:
Widget.hello(10)
Which means no instance of a widget class gets passed as a first param. You need to either set up the hello function to be static:
classWidget(object):
@staticmethoddefhello(value):
print("hello: " + str(value))
Widget.hello(10)
or call it on a specific object like this:
widget = Widget()
widget.hello(10)
Solution 2:
This is most probably because your hello function is not a class member. In that case you need not provide self in the method declaration....i.e. instead of hello(self,value) just say hello(value)
For example...this snippet works absolutely fine
defhello(value):
print'Say Hello to ' + value
hello('him')
If this is not the case then please provide your code snippet to help you further.
Post a Comment for "Takes Exactly 2 Arguments (1 Given) When Including Self"