You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. from functools import partial
  4. import sys
  5. sys.path.append('.')
  6. from example import Pet
  7. from example import Dog
  8. from example import Rabbit
  9. from example import dog_bark
  10. from example import pet_print
  11. polly = Pet('Polly', 'parrot')
  12. molly = Dog('Molly')
  13. roger = Rabbit('Rabbit')
  14. print(roger.name() + " is a " + roger.species())
  15. pet_print(roger)
  16. print(polly.name() + " is a " + polly.species())
  17. pet_print(polly)
  18. print(molly.name() + " is a " + molly.species())
  19. pet_print(molly)
  20. dog_bark(molly)
  21. try:
  22. dog_bark(polly)
  23. except Exception as e:
  24. print('The following error is expected: ' + str(e))
  25. from example import test_callback1
  26. from example import test_callback2
  27. from example import test_callback3
  28. from example import test_callback4
  29. from example import test_cleanup
  30. def func1():
  31. print('Callback function 1 called!')
  32. def func2(a, b, c, d):
  33. print('Callback function 2 called : ' + str(a) + ", " + str(b) + ", " + str(c) + ", "+ str(d))
  34. return d
  35. def func3(a):
  36. print('Callback function 3 called : ' + str(a))
  37. print(test_callback1(func1))
  38. print(test_callback2(func2))
  39. print(test_callback1(partial(func2, "Hello", "from", "partial", "object")))
  40. print(test_callback1(partial(func3, "Partial object with one argument")))
  41. test_callback3(lambda i: i + 1)
  42. f = test_callback4()
  43. print("func(43) = %i" % f(43))
  44. test_cleanup()