-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_project_lines.py
75 lines (68 loc) · 1.79 KB
/
count_project_lines.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
64
65
66
67
68
69
70
71
72
73
74
75
import codecs
files = ['TSW-1.py',
'StorageQt.py',
'Sound.py',
'BehaviourJournal.py',
'ReminderJackWidget.py',
'NewTaskDialog.py',
'AnimatedTray.py',
'Camera.py',
'TabSettingsWidget.py',
'Task.py',
'KeyboardLog.py',
'ScreenCapturer.py'
]
LINES = []
ls = set()
n_all =0
n_u = 0
for fname in files:
with codecs.open(fname,'r',encoding='utf-8') as f:
lines = f.readlines()
n_all+=len(lines)
LINES+=lines
n_u = len(set(tuple(LINES)))
print('all: ', n_all)
print('unique: ', n_u)
def splitter(line):
if len(line) == 0:
return []
line=line.strip().replace('\n','').replace('\r','')
#print(line)
res = ''
#for index,c in enumerate(line):
for c in line:
#if not c.isalpha() and c != ' ':
if not c.isalpha() and c != ' ' :
res+=' '
else:
res+=c
res=res.replace(' ',' ')
res=res.replace(' ',' ')
res=res.replace(' ',' ')
res=res.replace(' ',' ')
#print(len(res.split(' ')),res.split(' '))
return [item for item in res.split(' ') if len(item) > 2 ]
tokens=[]
for l in LINES:
if l != '':
tokens += splitter(l)
print(tokens)
i = input()
tokens = list(set(tuple(tokens)))
tokens.sort()
with codecs.open('tokens_9-11-2019.txt', 'a+',encoding='utf-8') as f:
for i,t in enumerate(tokens):
print(i,t)
f.write(t+'\n')
print(list(zip(tokens,range(0,len(tokens)-1))))
"""
tokens = {}
for l in LINES:
if len(l.strip()) != 0 and l.strip()[0] != #:
_l = l
for index, c in enumerate(l):
if c == '#':
_l = l[:index]
break
"""