t523.py 265 B

1234567891011121314151617
  1. class A:
  2. def __nonzero__(self):
  3. return "not the right value"
  4. try:
  5. print bool(A())
  6. except TypeError as e:
  7. print e
  8. class B:
  9. def __len__(self):
  10. return "not the right value"
  11. try:
  12. print bool(B())
  13. except TypeError as e:
  14. print e