有沒有辦法改變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.
'型(..)'不會**返回一個字符串... –