【发布时间】:2022-11-22 22:20:55
【问题描述】:
我有一个大文本文件,内容格式如下,我想删除两个第一个字符 11,我尝试通过不知道如何继续我的代码进行搜索。寻求帮助。谢谢
文件.txt
11112345,67890,12345
115432,a123q,hs1230
11s1a123,qw321,98765321
342342,121sa,12123243
11023456,sa123,d32acas2
我的代码
import re with open('in.txt') as oldfile, open('out.txt', 'w') as newfile: for line in oldfile: removed = re.sub(r'11', '', line[:2]): newfile.write(removed)预期结果:
112345,67890,12345
115432,a123q,hs1230
s1a123,qw321,98765321
342342,121sa,12123243
023456,sa123,d32acas2
【问题讨论】:
-
在您的预期结果中,第二行不应该是
5432,a123q,hs1230吗?
标签: python python-3.x