# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
# content ="";
import re
import os
writecontents = ''
with open("./demo.txt", encoding="utf-8") as fint:
content = fint.read()
pattern = re.compile("第w+章.*")
fint.close()
for i in re.findall(pattern, content):
writecontents = re.search(r'(?<=(' + i + ')).*(?=(------------))', content, re.S).group()
path = os.getcwd()+os.sep+'xiaoshou'
if not os.path.exists(path):
os.mkdir(path)
txtpath = path+os.sep + i + '.txt'
ispthat = os.path.isfile(txtpath)
if not ispthat:
write = open(txtpath, "w", encoding='UTF-8')
write.write(writecontents)
write.close()
print('写入成功')