Closed wuqingjing2010 closed 2 years ago
通过type 构建的 class 通过 op 正确打印,这个feature 能否实现?
from objprint import op class Action: pass def Category(label): return type("MCategory", (Action,), {"label": label, "__type__": "category"}) class ECategory(Action): def __init__(self,label): self.label = label self.__type__ = 'category' mm = Category('test') nn = ECategory('test') op(mm) op(nn) >> <class '__main__.MCategory'> >> <UCategory 0x1f2da7b2b00 >> .label = 'test' >> >
这个和type没关系。当你定义一个class的时候,它是有自己的__str__函数的。对于有默认的输出格式的object,objprint会在默认情况下使用他们自定义的输出格式。
type
__str__
objprint
你可以通过op(mm, honor_existing=False)来打印class变量。
op(mm, honor_existing=False)
OK 了 多谢
通过type 构建的 class 通过 op 正确打印,这个feature 能否实现?