-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasicmath.py~
More file actions
65 lines (45 loc) · 1.29 KB
/
basicmath.py~
File metadata and controls
65 lines (45 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
#############################
def logged_add(a, b):
print '### %s(%r, %r)' % ('add', a, b)
result = add(a, b)
print '### %s(%r, %r) --> %r' % ('add', a, b, result)
return result
# could change all calls to this... bleh
#############################
def logged(func):
def wrapper(a, b):
print '### %s(%r, %r)' % (func.func_name, a, b)
result = func(a, b)
print '### %s(%r, %r) --> %r' % (func.func_name, a, b, result)
return result
return wrapper
##############################
#def logged(func):
# def wrapper(*args):
# print '### %s(%s)' % (func.func_name, args)
# result = func(*args)
# print '### %s(%s) --> %r' % (func.func_name, args, result)
# return result
# return wrapper
#============================
def add(a, b):
"""add() adds things"""
return a + b
#add = logged(add)
def subtract(a, b):
"""subtract() subtracts two things"""
return a - b
#subtract = logged(subtract)
def even(a):
"""even() returns True if the value is even"""
return a % 2 == 0
#even = logged(even)
if __name__ == "__main__":
print '--- calling some math functions'
add(1, 1)
#logged_add(1,1)
add(2, 2)
subtract(2, 1)
even(42)
print '--- end'