【发布时间】:2021-07-09 06:07:01
【问题描述】:
我认为这个 Python 会话中的 AttributeError 消息
>>> class A: pass
...
>>> A().x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'x'
在 CPython 中 these lines 处的函数 _PyObject_GenericGetAttrWithDict 中实现:
if (!suppress) {
PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%U'",
tp->tp_name, name);
}
但是我在这个 Python 会话中找不到 AttributeError 消息的位置
>>> class A: __slots__ = ('x',)
...
>>> A().x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: x
在 CPython 中实现。您能否提供指向 GitHub 存储库中确切行的链接?
【问题讨论】:
标签: python attributeerror cpython python-internals