attrs module
Overview
from attr import attrs,attrib
@attrs
class Person:
name = attrib(type = str,default="")
age = attrib(type = int,default=0)
sex = attrib(type = str,default="")
if __name__ == '__main__':
first_person = Person("John",18,"M")
print(first_person)
Out:Person(name='John', age=18, sex='M')Use
Define attribute
参数
解释
__init__
Forced key-word
Validator
Convertor
Last updated