unless statement in Python

unless statement in Python

What about not in?:

if p4port not in line:
    labels.append(line)

Also i guess that you code can be modified then to:

if @ in line and line == l and p4port not in line:
    lineMatch = True
    labels.append(line.strip(n).split(@)[1] + <br>n)

Theres no unless statement, but you can always write:

if not some_condition:
    # do something

Theres also the not in operator as Artsiom mentioned – so for your code, youd write:

if @ in line and line == l:
    lineMatch = True
    line = line.strip(n)
    line = line.split(@)[1]
    line = line + <br>n
    if p4port not in line:
        labels.append(line)

… but Artsioms version is better, unless you plan to do something with your modified line variable later.

unless statement in Python

The error youre getting in your (rather drastically) edited question is telling you that the variable lineMatch doesnt exist – which means the conditions you specified for setting it werent met. It might help to add a line like LineMatch = False as the first line inside your outer for loop (before the first if statement), to ensure that it does exist.

Leave a Reply

Your email address will not be published. Required fields are marked *