1

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.

2
  • 2
    Please explain car_reg_number_in_application Commented May 25, 2021 at 11:05
  • 1
    I second @Darina , but let's take all the code needed to reproduce your problem, please! Definitions of all variables, etc. Commented May 25, 2021 at 11:07

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.