我只是要求我的代码过滤掉' - '和'+',但它也过滤了'//'它不应该过滤掉。
任何人都知道为什么会这样做?
with open("some_file_1.txt") as f, open("some_file_2.txt") as g:
flines = f.readlines()
glines = g.readlines()
d = difflib.Differ()
diff = d.compare(flines, glines)
with open('merged_tp.txt', 'w') as file_out:
for line in diff:
print line
new_line = re.sub('[+-?]', '', line)
file_out.write(new_line)
答案 0 :(得分:4)
字符集[+-?]
表示" +
和?
"之间的任何字符。
+
具有整数序数43. ?
具有整数序数63.范围43-63包括以下字符:+,-./0123456789:;<=>?
字符集[+-]
表示&#34; +
或-
&#34;,我认为这就是你想要的。