import re
def txt_cut(filel,keyws,cutby=r'[|]\s*'):
file = open(str(filel), "r")
txtlines = file.readlines()
data_is_need_num = 0
all_data = []
for line_num in range(len(txtlines)):
cur_line_data = txtlines[line_num]
for i in range(len(keyws)):
if keyws in cur_line_data:
data_is_need_num = data_is_need_num + 1
data_split = re.split(cutby, cur_line_data)
all_data.append(data_split)
if data_is_need_num == 0:
print("没有找到您想找的关键字:")
for i in range(len(keyws)):
print(keyws)
file.close()
return all_data
|