-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetAllCode.py
More file actions
27 lines (21 loc) · 839 Bytes
/
getAllCode.py
File metadata and controls
27 lines (21 loc) · 839 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Yu Sun'
import glob
import os
import re
def get_all_code(suffix):
for filename in glob.iglob("." + os.sep + '**' + os.sep + '*.' + suffix, recursive=True):
with open("all_code.txt", 'a', encoding='utf-8') as f1:
f1.writelines("File name:" + filename + "\n")
# For some comments are in Chinese, using ISO-8859-1
with open(filename, encoding='ISO-8859-1') as f:
for line in f.readlines():
if re.match(r'^\s*$', line):
pass
else:
# To remove comments
line_no_comments = str(line).split("#")[0]
f1.writelines(line_no_comments)
if __name__ == '__main__':
get_all_code("pl")