sample_python_attrs.py 199 B

123456789101112131415
  1. import attr
  2. @attr.s
  3. class Obj(object):
  4. x = attr.ib()
  5. y = attr.ib(default=1)
  6. obj1 = Obj(2)
  7. assert(obj1.x == 2)
  8. assert(obj1.y == 1)
  9. obj2 = Obj(3, 4)
  10. assert(obj2.x == 3)
  11. assert(obj2.y == 4)