if statement not working in python script

Advertisements

In this script I am searching through a list of products that I pulled down from shopify. I am using a basic if statement to check if the variable named msrp is not = to the value ‘None’. But for some reason this is not working.

for item in data['products']:
    used = False
    name = item['title']
    url = 'https://' + brand[0] + brand[1] + '/products/' + str(item['handle'])
    handel = item['handle']
    for variant in item['variants']:
        msrp =  variant['compare_at_price']
        salePrice = variant['price']
        if msrp != 'None':
            print(msrp)

When I run this it prints out a lot of integers for msrp but it still dose print out ‘None’. This is weird because I am checking to see if it is not ‘None’.

Here is part of what it prints out

None
None
20.00
20.00
None
None
None
None

>Solution :

Change this line

if msrp != 'None':

to

if msrp != None:

It’s None as in NoneType not of type(str)

Leave a ReplyCancel reply