-
Notifications
You must be signed in to change notification settings - Fork 7
/
slice2.py
57 lines (41 loc) · 1.13 KB
/
slice2.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
import random
def slice(file_name, n_files):
file = open(file_name + '.txt', 'r')
data = []
names = []
while (1):
line = file.readline()
dat = line.strip().split()
try:
num = int(dat[0].strip(','))
data.append(line)
# index =
except:
pass
if (line == ""):
break
# data.append(file.readline())
# print(data)
try:
test = data[1000:]
except:
print ("File not big enough")
return
start_adj = 1000
n_min = 1000
n_len = len(test)
for i in range(n_files):
start = start_adj + random.randint(0, n_len - start_adj - n_min)
end = start + n_min + random.randint(0, 500)
end = min(end, n_len)
# print(start, end)
fw_name = file_name + str(i) + '.txt'
names.append(fw_name)
fw = open(fw_name, 'w')
for j in range(start, end):
# print(j)
fw.write(test[j])
fw.close()
return names
files = slice('sample', 10)
print(files)