实例的默认 __str__ 方法

Default __str__ method for an instance

我有一个 class 没有 strrepr 方法。当我调用它时:

>>> from ingest.tpr import TPR
>>> t=TPR()
>>> t # that is, "repr(t)"
<ingest.tpr.TPR instance at 0x101eb8518>

这里的默认表示似乎是这样的:

"<${path_to_class} instance at ${memory_address}>"

这个默认实现是在哪里提供的?上面是 __repr__ 方法还是 __str__ 方法——我知道它在上面调用了 __repr__ 方法,但是 __str____repr__ 方法在开始时初始化为相同的东西,或者一个简单地调用另一个作为 "fall-back"。换句话说,默认的 __str____repr__ 在 python 中是什么样子的?它们将在哪里定义?

t.__repr__(这是 repr(t) 调用的内容)解析为(假设没有其他上游定义)object.__repr__,它由 Python 实现定义(例如, https://github.com/python/cpython/blob/master/Objects/typeobject.c#L3827)