简体   繁体   中英

Python find string in substring

if substring in string does not works properly. I get data from Webdriver (Selenium), and all data are strings. But finding substring from string doesn't work. It simply skips my loop without even not entering to it (goes to else statement).

View1_txt = View1_txt.replace('i', 'i').replace('İ', 'I')
View2_txt = View2_txt.replace('i', 'i').replace('İ', 'I')
for s in View1_txt.split():
    if s.isdigit() and len(s) == 4:
        if 1995 <= int(s) <= 2021:
            tp_year = int(s)
            print('year from TP1', tp_year)
            break
#SKIPS THIS LOOP
if car_reg_number_in_application in View1_txt:
    print('number CAR REG matches with TP1')
    car_model_in_reg_list = []
    car_model_in_reg_list.append(car_model_in_reg_form.upper())
    probability = process.extractOne(View1_txt, car_model_in_reg_list)
    if probability[1] >= 57:  # model in TP
        print('model in CAR REG matches with TP1')
        print(probability)
        boolean = check_sub_dict()
        if boolean:
            print('Inside SUB dict - ADD - everything is OK')
            return True  # Decline silently car registration -- Unblock from Schedule Block -- Upload Documents
        else:
            print('Inside MAIN dict')
            main_boolean = check_main_dict()
            if main_boolean:
                print('ADD - everything is OK')
                return True
            else:
                print("MAUNAL - not OK 1")
                return False
    else:
        print("MAUNAL - not OK 2")
        return False


#SKIPS THIS TOO AND GOES TO ELSE
elif car_reg_number_in_application in View2_txt:
    print('number CAR REG matches with TP2')

    car_model_in_reg_list = []
    car_model_in_reg_list.append(car_model_in_reg_form.upper())
    probability = process.extractOne(View1_txt, car_model_in_reg_list)
    if probability[1] >= 57:  # model in TP
        print('model in CAR REG matches with TP2')
        print(probability)
        boolean = check_sub_dict()
        if boolean:
            print('Inside SUB dict - ADD - everything is OK')
            return True  # Decline silently car registration -- Unblock from Schedule Block -- Upload Documents
        elif not boolean:
            print('Inside MAIN dict')
            main_boolean = check_main_dict()
            if main_boolean:
                print('ADD - everything is OK')
                return True
            else:
                print("MAUNAL - not OK 3")
                return False
        else:
            return False
    else:
        print("MAUNAL - not OK 4")
        return False
else:
    print("MAUNAL - not OK 5")
    return False
    #ENTER HERE

I checked all types and everything is a string, tried re search module didn't help.

in which case, the substring is probably not in the string.

Note that the condition is case sensative:

"hello" in "HELLO"
Out[1]: False

"hello".upper() in "HELLO".upper()
Out[2]: True

As it seems to be a car reg, you could also remove non alphanumeric characters:

import re
re.sub(r'\W+', '', car_reg_number_in_application)

Thanks, guys I solved my problem. My OCR tool took string O character as 0 integers so why it did not work! Thank you a lot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM