for element in uchar.strip('\n'):##必须加\n否则系统会把换行符也作为字符进行判断,会干扰程序的运行if element < u'\u4e00'or element > u'\u9fa5':
deftime_delete(self):for parent, dirnames, filenames in os.walk(self.rootdir):
for filename in filenames:
s = os.path.join(parent, filename)
f = open(s, 'r', encoding='utf8')
line = f.readlines()
f1 = open(s, 'w+', encoding='utf8')
al = re.compile(r'\[.*?\]')#默认匹配的是[]最短的模式,即'[1323][4567]'匹配的是[1323],而改为al = re.compile(r'\[.*\]')时匹配的是最长模式就是[1323][4567]try:
for i in range(0, len(line)):
result = re.sub(al, "\n", line[i])
f1.write(result)
except IndexError:
print("passttime_delete")
f.close()
f1.close()