簡體   English   中英

實例的默認 __str__ 方法

[英]Default __str__ method for an instance

我有一個沒有strrepr方法的 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM