+1 vote
in Programming Languages by (51.8k points)

I have defined a class FetchMLCovariates in my Python code. But when I try to use this class with some arguments, it gives the error: "TypeError: FetchMLCovariates() takes no arguments".

How can I fix it?

1 Answer

+2 votes
by (66.8k points)
selected by
Best answer

It seems that you forgot to define the __init__() function in your class. Without the __init__() function, you cannot pass arguments to your class, and it will give the error: "TypeError: class takes no arguments". To fix the error, define the __init__() function in your class.

Here is an example:

class HelloWorld:

    def __init__(self, name=None, greeting=None):

        self.name = name

        self.greeting = greeting

    def your_greeting(self):

        print(self.greeting + " " + self.name)

greet = HelloWorld(name="Mr. Apple", greeting="Good Morning")


The above code will print "Good Morning Mr. Apple"