【发布时间】:2020-04-23 13:41:52
【问题描述】:
我在使用 Brython 和使用 str 方法的继承时遇到了一个奇怪的情况。这是我使用Brython console 进行的测试:
>>> class A(object):
... def __str__(self):
... return "A __str__ output."
...
>>> class B(A):
... def __str__(self):
... return super().__str__() + " (from B)"
...
>>> x = A()
>>> x
<__main__.A object>
>>> y = B()
>>> y
<__main__.B object>
>>> str(y)
"<super: <class 'B'>, <B object>> (from B)"
我期待最后一行返回:
"A __str__ output. (from B)"
我在这里做错了吗?
【问题讨论】: