Discuss / Python / 为何我错这么多。。

为何我错这么多。。

Topic source

吾非名家

#1 Created at ... [Delete] [Delete and Lock User]

都是用老师的源码,但是。。报了5个Error,以下是输出结果:

EEEEE
======================================================================
ERROR: test_attr (__main__.TestDict)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mydict_test.py", line 19, in test_attr
    d = Dict()
  File "E:\learnpy\testDemo\mydict.py", line 4, in __init__
    super.__init__(**kw)
TypeError: descriptor '__init__' of 'super' object needs an argument

======================================================================
ERROR: test_attrerror (__main__.TestDict)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mydict_test.py", line 30, in test_attrerror
    d = Dict()
  File "E:\learnpy\testDemo\mydict.py", line 4, in __init__
    super.__init__(**kw)
TypeError: descriptor '__init__' of 'super' object needs an argument

======================================================================
ERROR: test_init (__main__.TestDict)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mydict_test.py", line 8, in test_init
    d = Dict(a=1, b='test')
  File "E:\learnpy\testDemo\mydict.py", line 4, in __init__
    super.__init__(**kw)
TypeError: descriptor '__init__' of 'super' object needs an argument

======================================================================
ERROR: test_key (__main__.TestDict)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mydict_test.py", line 14, in test_key
    d = Dict()
  File "E:\learnpy\testDemo\mydict.py", line 4, in __init__
    super.__init__(**kw)
TypeError: descriptor '__init__' of 'super' object needs an argument

======================================================================
ERROR: test_keyerror (__main__.TestDict)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mydict_test.py", line 25, in test_keyerror
    d = Dict()
  File "E:\learnpy\testDemo\mydict.py", line 4, in __init__
    super.__init__(**kw)
TypeError: descriptor '__init__' of 'super' object needs an argument

----------------------------------------------------------------------
Ran 5 tests in 0.002s

FAILED (errors=5)

吾非名家

#2 Created at ... [Delete] [Delete and Lock User]

额 在github文件页点raw,然后在raw里复制代码再粘贴就没事了。。应该是直接在文件页里复制代码会有问题吧。。。

吾非名家

#3 Created at ... [Delete] [Delete and Lock User]

不过,还想问下的是,测试通过是输出"."吗?

懿xing

#4 Created at ... [Delete] [Delete and Lock User]

根据你的错误提示:

TypeError: descriptor '__init__' of 'super' object needs an argument

是你自己定义的Dict类的init函数中除了self参数,还有另外一个参数,类似这样,注意最后那个括号里:

super(Dict, self).__init__(arg)

应该改成:

super(Dict, self).__init__()

因为init类似c++中的构造函数,在调用时会自动执行,而你没有传入任何参数


  • 1

Reply