-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
63 lines (48 loc) · 1.11 KB
/
functions.py
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
# functions
# pass for empty function
def name():
pass
# docs
def func_with_doc():
"""
Retuns 'hello'
:return:
"""
return 'hello'
# function that deconstruct an iterable
def expand(iterable):
return [x for x in iterable]
# function that returns a reference to another function
def gimme_function():
return expand
# just a string
a = 'dabana'
# service pattern
service = {
'counter': 0,
'username': a,
'expand': expand,
'gimme_function': gimme_function
}
print service['expand'](service['username'])
service['counter'] += 1
print service['gimme_function']()(service['username'])
service['counter'] += 1
print gimme_function()(service['username'])
service['counter'] += 1
# factory/module pattern
def factory():
counter = 0
return {
'counter': counter,
'username': a,
'expand': expand,
'gimme_function': gimme_function
}
# create 3 new services using the factory, they are independent (copy)
service1 = factory()
service1['counter'] += 1
print service1['counter']
service2 = factory()
print service2['counter']
service3 = factory()