python继承构造函数出现TypeError: unbound method __init__() must be called with Queue instance as first argument (got nothing instead),,python在构造函数中


python在构造函数中调用父类的__init__方法时出现下面的异常信息:

C:\Python27\python.exe "C:\Program Files\JetBrains\PyCharm 2.6.1\helpers\pydev\pydevd.py" --client 127.0.0.1 --port 49479 --file E:/outofmemory/svn/web/jobs/jobutils.pypydev debugger: startingConnected to pydev debugger (build 121.188)Traceback (most recent call last):  File "C:\Program Files\JetBrains\PyCharm 2.6.1\helpers\pydev\pydevd.py", line 1457, in <module>    debugger.run(setup['file'], None, None)  File "C:\Program Files\JetBrains\PyCharm 2.6.1\helpers\pydev\pydevd.py", line 1103, in run    pydev_imports.execfile(file, globals, locals) #execute the script  File "E:/outofmemory/svn/web/jobs/jobutils.py", line 57, in <module>    taskQueue = JobQueue('svn_task')  File "E:/outofmemory/svn/web/jobs/jobutils.py", line 28, in __init__    Queue.__init__(maxsize=maxsize)TypeError: unbound method __init__() must be called with Queue instance as first argument (got nothing instead)

这个异常的代码如下:

Class Foo(Bar):  def __init__(self):     Bar.__init__()

在构造函数中调用父类Bar的__init__方法时少传递了self参数,正确的做法应该是:

Class Foo(Bar):  def __init__(self):     Bar.__init__(self)

评论关闭