unless statement in Python

前端 未结 3 408

Is there an equivalent to the unless statement in Python? I do not want to append a line to a label if it has p4port in it:

for lin         


        
3条回答
  •  余生分开走
    2021-01-07 18:50

    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] + '
    \n')

提交回复
热议问题