blob: 4e75e1714becce0ec10f00050d3b3e2ff69483e1 [file] [log] [blame]
Wenzel Jakob57082212015-09-04 23:42:12 +02001#!/usr/bin/env python
2from __future__ import print_function
Wenzel Jakob38bd7112015-07-05 20:05:44 +02003import sys
4sys.path.append('.')
5
6from example import Pet
7from example import Dog
8from example import dog_bark
9from example import pet_print
10
11polly = Pet('Polly', 'parrot')
12molly = Dog('Molly')
13print(polly.name() + " is a " + polly.species())
14pet_print(polly)
15print(molly.name() + " is a " + molly.species())
16pet_print(molly)
17dog_bark(molly)
18try:
19 dog_bark(polly)
20except Exception as e:
21 print('The following error is expected: ' + str(e))
22
23from example import test_callback1
24from example import test_callback2
25from example import test_callback3
Wenzel Jakob281aa0e2015-07-30 15:29:00 +020026from example import test_callback4
27from example import test_callback5
Wenzel Jakob38bd7112015-07-05 20:05:44 +020028from example import Example5
29
30def func1():
31 print('Callback function 1 called!')
32
Wenzel Jakob7b8e0322015-08-28 17:49:15 +020033def func2(a, b, c, d):
34 print('Callback function 2 called : ' + str(a) + ", " + str(b) + ", " + str(c) + ", "+ str(d))
Wenzel Jakob38bd7112015-07-05 20:05:44 +020035 return c
36
37class MyCallback(Example5):
38 def __init__(self, value):
39 Example5.__init__(self, self, value)
40
41 def callback(self, value1, value2):
42 print('got callback: %i %i' % (value1, value2))
43
44print(test_callback1(func1))
45print(test_callback2(func2))
46
47callback = MyCallback(3)
48test_callback3(callback, 4)
Wenzel Jakob281aa0e2015-07-30 15:29:00 +020049
50test_callback4(lambda i: i+1)
51f = test_callback5()
52print("func(43) = %i" % f(43))