Undetected if condition

Question:

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?

Asked By: BQuist

||

Answers:

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.

Answered By: Rahul K P
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.