Jod*_*992 0 python program-entry-point typeerror python-2.7
我正在尝试main()在Python 2.7.11中创建一个类文件并运行它,但Python声称我需要传递main()一个参数.
def main(self):
howManyBadCrops = BadCropsDetector() # My class
# a bunch of stuff goes here that runs the module....
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
为什么会这样?这是我的终端输出:
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)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,您不需要self函数定义中的参数main.这是因为main显然是模块级函数,您只需要指定self何时编写包含在类中的函数(即方法).
只需从定义中删除它:
def main():
Run Code Online (Sandbox Code Playgroud)