论语是儒家学派的经典著作之一...
问题1:
fi = open("论语.txt", "r")
fo = open("论语-原文.txt", "w")
a=0
for line in fi:#每次读完,line都是一个字符串
if a==1 and line.count("【注释】")==0 and line.count("【原文】")==0:
line=line.strip("
")
if line.strip():#去掉各种符号后,如果不是空字符串
fo.write("{}
".format(line))
if line.count("【原文】")>0:
a=1#利用a的值来控制写或者不写
if line.count("【注释】")>0:
a=0
fi.close()
fo.close()
问题2:
fi = open("论语-原文.txt", "r")
fo = open("论语-提纯原文.txt", "w")
for line in fi:
for k in range(100):#括号内序号的编号
line=line.replace('('+str(k)+')','')
fo.write(line)
fi.close()
fo.close()