因此,在Python中,我使用.isdigit()
检查它是否是一个数字,如果是,我将忽略它。但是,我的代码正在删除一行中的每个数字,除了第一个数字1
。我已经做完了。它不仅仅是捕捉1
。为什么会发生这种情况?为什么我的程序会删除除1
之外的所有其他数字
下面是一个示例文件
1
00:00:09,068 --> 00:00:11,068
Ordinarily,
I'm a rule follower,
2
00:00:11,103 --> 00:00:12,369
But when someone tells me
3
00:00:12,404 --> 00:00:14,338
I can't bring my own snacks
into their stadium,
这就是结果。其中1
不应包括在内
1
Ordinarily,
I'm a rule follower,
But when someone tells me
I can't bring my own snacks
into their stadium,
下面是我的代码
for line in lines:
line = line.strip()
if len(line.strip()) != 0 and line != 1 and line != "1":
if (not line.isdigit()) and ('-->' not in line):
line = del_brackets(line)
line = ' '.join(''.join(' ' if ch in exclude else ch for ch in line).split())
line = re.sub(r'\.\.\.', ' ', line)
outfile.write(line.lstrip() + "\n")
目前没有回答
相关问题 更多 >
编程相关推荐