0

i have a variable data which have a value of [('01:02,02:52,03:30,03:31',)], and a srt file with some of its content be like:

    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>

now i want to check if any element of my data eg: 01:02 or 03:30 or any other separately is present in the srt file or not. For eg: 01:02 is present below 24 numbered 00:01:02,016 --> 00:01:08,225

here is python file but no outcome:

    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()

please help me out....

MrE
  • 13
  • 5
  • It isn't clear what you are asking. Are you having trouble finding `s` in `text`? – wwii Jan 07 '18 at 14:51
  • no sir, actually there a variable "data" which have a value of **[('01:02,02:52,03:30,03:31',)]** ,now i want to check if any sub element of data variable for eg: ** 01:02** is present in the "one .srt" file or not – MrE Jan 07 '18 at 15:31
  • I don't see you trying to do that in any part of the code you posted. Please read [mcve]. – wwii Jan 07 '18 at 15:41
  • Possible duplicate of [How to search for a string in text files?](https://stackoverflow.com/questions/4940032/how-to-search-for-a-string-in-text-files) – wwii Jan 07 '18 at 15:46
  • no that is different i want to compare a part o my data to the file and not the whole data. Actually im facing problem in comparing elements of data to file – MrE Jan 07 '18 at 16:07
  • So your question is `how do I split a string into its *relevant* parts?` - and all the rest of your post is fluff? – wwii Jan 07 '18 at 16:09
  • Please take the time to read [ask] and the other links on that page. You should invest some time working your way through [the Tutorial](https://docs.python.org/3/tutorial/index.html), practicing the examples. It will give you an introduction to the tools Python has to offer and you may even start to get ideas for solving your problem. – wwii Jan 07 '18 at 16:10
  • ohk, i do understand their might be some issues in my question but, can please tell me how to resolve my issue about my searching the elements – MrE Jan 07 '18 at 16:16

1 Answers1

0

There are few things. First, you iterate over infinite loop, there is no exit. Second you check for whole words instead part of one word. Here are my suggestions:

...
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
    ...