Jodo1992
Jodo1992

Reputation: 733

TypeError: main() takes exactly 1 argument (0 given)

I'm trying to create a main() in a class file in Python 2.7.11 and run it, but Python is claiming I need to pass main() an argument.

def main(self):
    howManyBadCrops = BadCropsDetector() # My class
    # a bunch of stuff goes here that runs the module....

if __name__ == "__main__":
    main()

Why is this happening? Here is my terminal output:

Traceback (most recent call last):
  File "badCropsDetector.py", line 11, in <module>
    class BadCropsDetector:
  File "badCropsDetector.py", line 66, in BadCropDetector
    main()
TypeError: main() takes exactly 1 argument (0 given)

Upvotes: 0

Views: 10188

Answers (1)

wim
wim

Reputation: 362945

In this context, you don't need the self argument in the function definition of main. This is because main is plainly a module level function, you only need to specify the self when you are writing a function contained inside a class (i.e. a method).

Simply remove it from the definition:

def main():

Upvotes: 4

Related Questions