re.sub的时候都带r防止转义了,为什么还是不行呢 有人解答下吗
import re
with open(r'D:\text.txt', 'a+') as file:
file.seek(0)
list = file.readlines()
for i, j in enumerate(list):
if j.find(r"print u'\nhello\n'") > -1:
print(666)
list[i] = re.sub(r"print u'\nhello\n'", '', j)
print(list)
file.seek(0)
file.truncate()
file.write(''.join(list))