source:
doc/papers/concurrency/examples/Format.py
@
4b3b352
Last change on this file since 4b3b352 was a573c22, checked in by , 5 years ago | |
---|---|
|
|
File size: 686 bytes |
Line | |
---|---|
1 | def Format(): |
2 | try: |
3 | while True: |
4 | for g in range( 5 ): # groups of 5 blocks |
5 | for b in range( 4 ): # blocks of 4 characters |
6 | while True: |
7 | ch = (yield) # receive from send |
8 | if '\n' not in ch: |
9 | break |
10 | print( ch, end='' ) # receive from send |
11 | print( ' ', end='' ) # block separator |
12 | print() # group separator |
13 | except GeneratorExit: # destructor |
14 | if g != 0 | b != 0: # special case |
15 | print() |
16 | |
17 | input = "abcdefghijklmnop\nqrstuvwx\nyzxxxxxxxxxxxxxx\n" |
18 | |
19 | fmt = Format() |
20 | next( fmt ) # prime generator |
21 | for i in input: |
22 | fmt.send( i ); # send to yield |
23 | |
24 | # Local Variables: # |
25 | # tab-width: 4 # |
26 | # compile-command: "python3.7 Format.py" # |
27 | # End: # |
Note: See TracBrowser
for help on using the repository browser.