【发布时间】:2021-11-16 03:26:36
【问题描述】:
我正在编写一些 python 代码来评估文件的每一行,如果该行是一个数字,它应该返回 false 并忽略该行。此代码来自https://github.com/geoff604/sbv2txt/blob/master/README.md,我正在努力修改它。
但是,无论哪一行被传递给 IsNumeric() 函数,它的计算结果仍然为 False。我将相同的数字硬编码为字符串"2",并将其正确评估为True。
在评估文本行时我是否遗漏了什么?
import sys
def isCaptionText(lineIndex):
if lineIndex.isnumeric():
print('True')
return False
else:
return lineIndex
if len(sys.argv) < 3:
print('Arguments: [source sbv filename] [destination txt filename]')
sys.exit()
with open(sys.argv[1]) as f1:
with open(sys.argv[2], 'a') as f2:
lines = f1.readlines()
for index, line in enumerate(lines):
if isCaptionText(line):
f2.write(line)
print('Output complete. File written as ' + sys.argv[2])
我正在分析的文件是我将在下面以缩写形式列出的文本。
2
00:00:04,360 --> 00:00:08,861
St. Louis' home for arts,
education and culture.
3
00:00:08,861 --> 00:00:11,444
(upbeat music)
4
00:00:12,290 --> 00:00:13,610
- [Woman] But we're in a global pandemic.
5
00:00:13,610 --> 00:00:16,000
We're also in a global blood shortage.
6
00:00:16,000 --> 00:00:18,230
- [Man] The more I dug,
the more it took me back
【问题讨论】:
标签: python python-3.x isnumeric