Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

if statement not working in python script

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading