Home > front end >  Undetected if condition
Undetected if condition

Time:08-26

I am trying to use an if condition in conjuction with a for loop. I was confident this would work, but i'm seeming to have difficulty. I am able to print the information from the api, but when I try to if condition with results, something isn't getting detected.

Code:

for example in examples:
    profile = requests.get(api, params=params)
    hunter = json.loads(profile.content)

    accept_All = hunter['data']['accept_all']
    verif = hunter['data']['verification']['status']

    first_name = hunter['data']['first_name']
    last_name = hunter['data']['last_name']
    domain = hunter['data']['domain']
    email_address = hunter['data']['email']

    print(hunter['data']['verification']['status'])
    print(hunter['data']['accept_all'])

    if accept_All == 'False' and verif == 'valid':
        validEmails.append([first_name, last_name, domain, email_address])
        print("test")

print(validEmails)
print("Out of the Loop")

Output:

valid
False
[]
Out of the Loop

What am I overlooking?

CodePudding user response:

You should change to this,

if not accept_All and verif == 'valid':
    validEmails.append([first_name, last_name, domain, email_address])
    print("test")

Because False will be a boolean value, not a string.

  • Related