-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest.py
More file actions
53 lines (46 loc) · 1021 Bytes
/
test.py
File metadata and controls
53 lines (46 loc) · 1021 Bytes
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
def consumer(func):
def wrapper(*args,**kw):
gen = func(*args, **kw)
gen.next()
return gen
wrapper.__name__ = func.__name__
wrapper.__dict__ = func.__dict__
wrapper.__doc__ = func.__doc__
return wrapper
@consumer
def feed_sequence(destination):
input_queue = _queue.Queue()
#def input_seq():
def summer(input_seq):
"""
pass a sequence of two-element sequences.
returns a generator which returns the sum of the second item of each input element
"""
total = 0
for x in input_seq:
total += x
yield total
#print summer(xrange(4)).next()
def add1(input_seq):
for x in input_seq:
yield x+1
def make_gen():
yield
print("1")
val = yield
print("2: val = %s" % val)
while True:
print("3: val = %s" % val)
val = yield val
def make_f():
in_gen = make_gen()
in_gen.send(None)
out_gen = add1(in_gen)
def wrapper(x):
print("f1: x = %s" % x)
in_gen.send(x)
return out_gen.next()
return wrapper
f = make_f()
for x in range(4):
print f(x)