1
我:運行屬性驗證__attrs_post_init__結束後才
@attr.s
class Example:
number = attr.ib(validator=attr.validators.instance_of(int), init=False)
def __attrs_post_init__(self):
self.number = 'string'
print('It seems, validation was running before:(')
t = Example()
如何正確設置驗證嗎?我想在實例化後驗證self.number。
什麼是attr? – warvariuc
你好@warvariuc,這是一個包https://github.com/python-attrs/attrs –