有没有办法改变CLASS OBJECT以便type(object)
报告一个自定义的字符串?一种重写'type()'报告的方法
class MyClass(object):
def __init__(self, t):
if 'detector' in t:
my_type_string = "I am set as a detector."
else:
my_type_string = "I am set as a broadcaster."
>>> o = MyClass('detector')
>>> type(o)
I am set as a detector.
'型(..)'不会**返回一个字符串... –