DevOps | Cloud | Analytics | Open Source | Programming





How To Fix Python TypeError - "Class Takes No Arguments (1 Given)"



This is a post to explain How To Fix Python TypeError - "Class Takes No Arguments (1 Given)".  This error occurs due to incorrect use of self parameter.  

Fix - class takes no arguments (1 given) :

Consider below example -


class A:
  def func():
    print("Class Test")

a = A()
a.func()

Gives Error


TypeError: say() takes no arguments (1 given)

Reason and Fix -

  • The errors happens because the func() is a method within a Class. As such the first argument is expected to be a "self" parameter.
    • "self" parameter contains a Reference to itself.
    • Python pass the "self" parameter internally by default when calling a method - whether used or not used by the method does not matter !
  • To fix the error , send the "self" parameter as shown below -

class A:
  def func(self):
    print("Class Test")

Alternatively if you do not want to use the "self" parameter (for whatever reason !) , you can use "@staticmethod" . See below -


class A:
  @staticmethod
  def func(self):
     print("Class Test")

Hope this post helps.  

Other Interesting Reads -

 


python constructor takes no arguments, typeerror: this constructor takes no arguments lcd, typeerror this constructor takes no arguments error in python, typeerror class() takes no arguments, constructor that takes no arguments java, constructor that takes no arguments c# class this constructor takes no arguments, typeerror employee takes no arguments, constructor in python, typeerror this constructor takes no arguments error in python, typeerror: this constructor takes no arguments python, typeerror: this constructor takes no arguments lcd, typeerror class() takes no arguments, constructor that takes no arguments java, constructor that takes no arguments c#, constructor in python, class this constructor takes no arguments, typeerror employee takes no arguments, typeerror example takes no arguments ,typeerror api takes no arguments ,typeerror shuupadminmiddleware takes no arguments ,typeerror type takes no arguments ,typeerror run takes no arguments (1 given) ,typeerror file takes no arguments ,typeerror actor takes no arguments ,typeerror dataset takes no arguments ,typeerror class takes no arguments python ,typeerror example takes no arguments ,typeerror type takes no arguments ,typeerror organisation takes no arguments ,typeerror api takes no arguments ,typeerror dataset takes no arguments ,typeerror parkedvehicle takes no arguments ,typeerror actor takes no arguments ,python typeerror class takes no arguments ,python class typeerror this constructor takes no arguments ,python class typeerror object() takes no parameters