[英]Python 3.5 : TypeError: __init__() got an unexpected keyword argument 'nosigint'
I am using Python 3.5 to do doctest. 我使用Python 3.5来做doctest。 There is always an error: 始终存在错误:
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'
It seems that the error occurs in the doctest.py file, but not in my own code. 似乎错误发生在doctest.py文件中,但不在我自己的代码中。
I hope to define a class which is similar to dict. 我希望定义一个类似于dict的类。 My code is: 我的代码是:
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()
Can you help me with this? 你能帮帮我吗?
It looks like you are using the Anaconda Python distribution. 看起来您正在使用Anaconda Python发行版。
Are you running using the Spyder IDE? 你在使用Spyder IDE运行吗?
There is an open bug in Spyder's issue tracker. Spyder的问题跟踪器中存在一个漏洞 。
The suggested work-around involves modifying the source of pdb
and doctest
. 建议的解决方法涉及修改pdb
和doctest
的源代码。
For a shoddy quick fix you can remove the 对于粗制滥造的快速修复,你可以删除
nosigint=True
argument from thepdb.Pdb.init
indoctest.py
nosigint=True
pdb.Pdb.init
中doctest.py
nosigint=True
参数and change the default value of
nosigint
toTrue
inpdb.py
并在pdb.py
的默认值nosigint
为True
if you are being affected by this bug, you can encourage the folk who make Spyder to fix it by Subscribing to Notifications about this issue on GitHub 如果你受到这个bug的影响,你可以通过在GitHub上订阅有关此问题的通知来鼓励让Spyder修复它的人
There is another potential solution that I have used to work around this bug. 还有另一个我用来解决这个bug的潜在解决方案。 You can add an __init__
method to the SpyderPdb
class that sets a default value for the missing nosigint
argument. 您可以向SpyderPdb
类添加__init__
方法,该方法为缺少的nosigint
参数设置默认值。
I'm using the WinPython distribution to get Spyder, but it's probably something similar for Anaconda. 我正在使用WinPython发行版来获取Spyder,但它可能类似于Anaconda。 For Python 3.5+ it's in: \\WinPython...\\python...\\Lib\\site-packages\\spyder\\utils\\site\\sitecustomize.py 对于Python 3.5+,它位于:\\ WinPython ... \\ python ... \\ Lib \\ site-packages \\ spyder \\ utils \\ site \\ sitecustomize.py
For earlier versions it might be in ...\\Lib\\site-packages\\spyderlib\\widgets\\externalshell\\sitecustomize.py 对于早期版本,它可能位于... \\ Lib \\ site-packages \\ spyderlib \\ widgets \\ externalshell \\ sitecustomize.py
class SpyderPdb(pdb.Pdb):
def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, nosigint=False):
super(pdb.Pdb, self).__init__()
( Spyder开发人员 )这个问题将在Spyder 3.1.4中修复,将于2017年3月中旬发布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.