发布网友
共2个回答
热心网友
伪代码:
1、遍历文件夹下所有txt文件
rootdir = '/path/to/xx/dir' # 文件夹路径2、读取txt文件里的内容,通过正则表达式把txt里多篇文章拆分开来。得到一个列表:['{xx1}##NO', '{xx2}', '{xx3}##NO']
3、把上面得到的list写到一个新的临时文件里,比如:xx_tmp.txt,然后:shutil.move('xx_tmp.txt', 'xx.txt') 覆盖掉原来的文件
热心网友
a = "{从前有座山,山里有座庙...}{小白是个学生...}{从前有座山,山里有个老和尚...}"
b = "从前"
c = "山"
d = a.split("{")
for i in range(len(d)):
if b in d[i] and c in d[i]:
d[i] = d[i] + "##NO"
e = "{".join(d)
print e