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.

56 lines
1.5 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_callback5
  30. from example import test_cleanup
  31. def func1():
  32. print('Callback function 1 called!')
  33. def func2(a, b, c, d):
  34. print('Callback function 2 called : ' + str(a) + ", " + str(b) + ", " + str(c) + ", "+ str(d))
  35. return d
  36. def func3(a):
  37. print('Callback function 3 called : ' + str(a))
  38. print(test_callback1(func1))
  39. print(test_callback2(func2))
  40. print(test_callback1(partial(func2, "Hello", "from", "partial", "object")))
  41. print(test_callback1(partial(func3, "Partial object with one argument")))
  42. test_callback3(lambda i: i + 1)
  43. f = test_callback4()
  44. print("func(43) = %i" % f(43))
  45. f = test_callback5()
  46. print("func(number=43) = %i" % f(number=43))
  47. test_cleanup()