# !/usr/bin/env python 3
# encoding: utf-8
def split_line(line,n):
if len(line) <=n:
return line
else:
s = ""
for i in range(len(line)-n+1):
s += line[i:i+n]
s += ";"
s += "\n"
return s
if __name__ == '__main__':
# 词组长度
seq_len = 2
# 读取文件路径
path = "./test.txt"
file = open(path,'r',encoding='utf-8')
# 保存结果路径
result_path = "./result.txt"
result_file = open(result_path,'w',encoding='utf-8')
for line in file:
temp = line.strip()
result_file.writelines(split_line(temp,seq_len))
# 关闭文件
file.close()
result_file.close()# 我用你给的文本做了测试;下面是输出
单一;一结;结构;
象形;形字;
不是;是槌;槌的;的打;打击;
乃是;是水;水的;的载;载歌;歌载;载舞;
使鹅;鹅卵;卵石;石臻;臻于;于完;完美;
渐臻;臻佳;佳境;
日臻;臻完;完善;
左右;右结;结构;
友谊;谊的;的主;主要;要效;效用;用之;之一;一就;就在;在使;使人;人心;心中;中的;的愤;愤懑;懑抑;抑郁;郁之;之气;气得;得以;以宣;宣泄;泄弛;弛放;
这些;些不;不平;平之;之气;气是;是各;各种;种的;的情;情感;感都;都可;可以;以引;引起;起的;