gpt4 book ai didi

python - 检查python中的srt文件中是否存在原始数据的任何元素

转载 作者:行者123 更新时间:2023-11-29 18:03:17 25 4
gpt4 key购买 nike

我有一个值为 [('01:02,02:52,03:30,03:31',)] 的变量数据,以及一个 srt 文件,其部分内容如下:

    23
00:00:59,025 --> 00:01:06,042
can read and display documents that

24
00:01:02,016 --> 00:01:08,225
contain<font color="#E5E5E5"> HTML so Firefox Google Internet</font>

25
00:01:06,042 --> 00:01:09,851
<font color="#CCCCCC">Explorer they all do the same thing</font>

26
00:01:08,369 --> 00:01:12,630
<font color="#E5E5E5">they're going</font><font color="#CCCCCC">
to</font><font color="#E5E5E5"> take that</font><font color="#CCCCCC">
document and</font>

现在我想检查 srt 文件中是否存在我的数据的任何元素,例如:01:02 或 03:30 或任何其他单独的元素。例如: 01:02 出现在编号为 00:01:02,016 --> 00:01:08,225

的 24 下面

这是 python 文件,但没有结果:

    import mysql.connector
import numpy as np
conn= mysql.connector.connect
(user="root",password="",host="localhost",database="videojs")

# prepare a cursor object using cursor() method
cursor = conn.cursor()

def read_from_db():

cursor.execute("select time_arr from info where id ='52'")
data=cursor.fetchall()
print(data)
#Open the file
fobj = open("one.srt")
text = fobj.read().strip().split()

#Conditions
while True:
s = input("Enter a string: ") #Takes input of a string from user
if s == "": #if no value is entered for the string
continue
if s in text: #string in present in the text file
print("Matched")
break
else: #string is absent in the text file
print("No such string found,try again")
continue
fobj.close()


read_from_db()

请帮帮我......

最佳答案

事情很少。首先,你迭代无限循环,没有导出。其次,检查整个单词而不是一个单词的一部分。以下是我的建议:

...
text = fobj.read().strip().split() # this will create array of worlds
working = True
while working:
s = input("Enter a string: ") #Takes input of a string from user
if s == "": #if no value is entered for the string
continue
for t in text: # iterate over all words in file
if s in t: # check if input string is part of single word
print("Matched")
working = False
break
...

关于python - 检查python中的srt文件中是否存在原始数据的任何元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48138209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com