0

Im new to Python and am having issues with lists, elements,etc. I have this code:

order_payment = Api.which_api('order_payments', 'None', '26', 'None')

# now that we have info from order_payment, obtain the rest of the vars we need
order_id      = order_payment['order_id']

order_payment = Api.which_api('order_payments', 'None', '26', 'None')
orders        = Api.which_api('orders', 'None', order_id, 'items')

# your loop
for orders in orders['items']:
    oid  = orders['order_id']
    item = orders['item_name']
    print(item)

    sub = 'Download'
    print (s for s in item if sub in s)

When I do print(item) I get this returned: Norton Antivirus 2014 - Download - 1 User / 1 PC - 1 Year Subscription

I want to check this variable to see if it has Download in it(like this one does) I looked on here and found the code Im trying(sub = 'Download') but that is not working. Basically Im trying to set up a if condition. If this element 'item_name' has 'Download' in it do this. How do i check the vairable for this

2 Answers 2

1

Use the in operator

if "Download" in item: print

Sign up to request clarification or add additional context in comments.

Comments

0

My suggestion to you would be to use try and except in your python code for better results.

try :
   item = orders['item_name']
   print(item)

   sub = 'Download'
   print (s for s in item if sub in s)
except:
   pass

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.