По сравнению с python2 журнал ошибок в python3 намного длиннее и включает в себя места возникновения ошибки в импортированных модулях. В большинстве случаев я просто ищу ошибки в собственном коде, и эта дополнительная информация усложняет мне поиск ошибки в моем собственном коде. Можно ли изменить регистрацию ошибок в python3, чтобы она была более похожа на запись ошибок python2?
Пример ниже. Я бы предпочел получать только первую ошибку «трассировки».
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-69464cb62aa7>", line 25, in <module>
msep0_avg['s{0}ch{1}'.format(shot, ch)]), msep0_std['s{0}ch{1}'.format(shot, ch)])
IndexError: tuple index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2040, in showtraceback
stb = value._render_traceback_()
AttributeError: 'IndexError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/IPython/core/ultratb.py", line 1101, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "/opt/anaconda3/lib/python3.7/site-packages/IPython/core/ultratb.py", line 319, in wrapped
return f(*args, **kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/IPython/core/ultratb.py", line 353, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "/opt/anaconda3/lib/python3.7/inspect.py", line 1502, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
File "/opt/anaconda3/lib/python3.7/inspect.py", line 1460, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "/opt/anaconda3/lib/python3.7/inspect.py", line 696, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "/opt/anaconda3/lib/python3.7/inspect.py", line 742, in getmodule
os.path.realpath(f)] = module.__name__
AttributeError: module has no attribute '__name__'