-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdivision.py
More file actions
42 lines (35 loc) · 1.06 KB
/
Copy pathdivision.py
File metadata and controls
42 lines (35 loc) · 1.06 KB
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
# _*_coding_*_ utf-8
# __date__ = '17-9-7 下午2:04'
import os
import time
def mkSubFile(lines, head, srcName, sub):
[des_filename, extname] = os.path.splitext(srcName)
filename = des_filename + '_' + str(sub) + extname
print('make file: %s' % filename)
fout = open(filename, 'w')
try:
fout.writelines([head])
fout.writelines(lines)
return sub + 1
finally:
fout.close()
def splitByLineCount(filename, count):
fin = open(filename, 'r')
try:
head = fin.readline()
buf = []
sub = 1
for line in fin:
buf.append(line)
if len(buf) == count:
sub = mkSubFile(buf, head, filename, sub)
buf = []
if len(buf) != 0:
sub = mkSubFile(buf, head, filename, sub)
finally:
fin.close()
if __name__ == '__main__':
begin = time.time()
splitByLineCount('/run/media/abin/备份专用盘/以入库数据/20170908/QQqun1/qun1.csv', 800000)
end = time.time()
print('time is %d seconds ' % (end - begin))