-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreams.py
49 lines (39 loc) · 1015 Bytes
/
streams.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
#!/usr/bin/env python3
__author__ = "John Petersen"
__version__ = "0.0.1"
__license__ = "GNU General Public License 3.0"
import io
import re
import sys
from util import *
from timing import *
from functional import *
def yesman(*y, **z):
return True
def iscomment(src, *y, **z):
return re.match(r'^\s*#', src) != None
def trim(src, to = ''):
return re.sub(r'^\s+|\s+$', to, src)
def compress(src, to = ' ', pat = r'\S+'):
return to.join(re.findall(pat, src))
def noncomment(src):
return re.sub(r'\s*#.*', '', src)
def lines(fname, dest = [], pred = yesman, fn = identity):
f = io.open(fname)
for l in f:
if(pred(l)):
dest.append(fn(l))
f.close()
return dest
if(__name__ == '__main__'):
i = 0
coms = []
noncoms = []
fname = 'share/test.txt'
lines(fname, noncoms, yesman, noncomment)
#lines(fname, noncoms, fnot(iscomment))
#
for line in noncoms:
i = i + 1
print(f'{i}. "{line[0:-1]}"')
sys.exit(0)