【发布时间】:2012-03-02 01:36:06
【问题描述】:
我了解以下 Python 代码:
>>> class A(object):
... def __str__(self):
... return "An instance of the class A"
...
>>>
>>> a = A()
>>> print a
An instance of the class A
现在,我想更改
的输出>>> print A
<class '__main__.A'>
我需要重载哪个函数才能做到这一点?即使该类从未实例化,该解决方案也必须有效。 Python 2.x 和 3 的情况是否不同?
【问题讨论】:
-
在提问之前,您有checked 的现有答案吗?
-
我试过了,其实没找到。