vendredi 16 juin 2017

Python 3.6.1: How to exit a nested IF statement correctly

I am using scrapy and building a nested if statement. What I need the code to do is:

  1. Check if the term 'text' exists anywhere in a list. It is assigned the value 'text'.
  2. If 'text' DOES NOT contain 'some phrase', assign the value 'NA'.
    Store that value as a scrapy item named "a".
  3. If 'text' DOES contain 'some phrase', do something with 'text'.

My .py code so far:

    #get all items containing 'text'
    text = [i for i in list if "text" in i]

    if text:
        if 'some phrase' in x:
            pass
        else:
            <do something>

    else:
        item["a"] = "NA"

I tried using 'pass', but it seems to still be processing the if statement. What I need it to do is exit the nested if statement altogether (i.e., don't do anything with the text at all) and store the value "NA" in the scrapy item named "a".

Where am I going wrong?

Aucun commentaire:

Enregistrer un commentaire