[英]Default __str__ method for an instance
我有一個沒有str
或repr
方法的 class 。 當我稱之為:
>>> 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__
方法是否在開始時都初始化為相同的東西,或者只是簡單地調用另一個作為“倒退”。 換句話說,默認的__str__
和__repr__
在 python 中是什么樣子的,在哪里定義?
t.__repr__
(which is what repr(t)
calls) resolves to (assuming no other upstream definitions) object.__repr__
, which is defined by the Python implementation (for example, https://github.com/python/cpython/blob /master/Objects/typeobject.c#L3827 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.