我正在使用Python 3.5来做doctest。总是有一个错误:Python 3.5:TypeError:__init __()得到了一个意外的关键字参数'nosigint'
File "D:\Program Files\Anaconda\lib\doctest.py", line 357, in __init__
pdb.Pdb.__init__(self, stdout=out, nosigint=True)
TypeError: __init__() got an unexpected keyword argument 'nosigint'
看来,错误发生在doctest.py文件中,但不是在我自己的代码中。
我希望能定义一个类似于dict的类。我的代码是:
class Dict(dict):
'''
Simple dict but also support access as x.y style.
>>> d1 = Dict()
>>> d1['x'] = 100
>>> d1.x
100
>>> d1.y = 200
>>> d1['y']
200
>>> d2 = Dict(a=1, b=2, c='3')
>>> d2.c
'3'
>>> d2['empty']
Traceback (most recent call last):
...
KeyError: 'empty'
>>> d2.empty
Traceback (most recent call last):
...
AttributeError: 'Dict' object has no attribute 'empty'
'''
def __init__(self, **kw):
super(Dict, self).__init__(**kw)
def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise AttributeError(r"'Dict' object has no attribute '%s'" % key)
def __setattr__(self, key, value):
self[key] = value
if __name__=='__main__':
import doctest
doctest.testmod()
你能帮助我吗?
我正在使用Spyder IDE。谢谢。 – Dawn