除非Python中的语句

发布于 2021-01-29 16:31:09

unlessPython中的语句是否等效?我不想在标签上添加一行p4port

for line in newLines:
    if 'SU' in line or 'AU' in line or 'VU' in line or 'rf' in line  and line.find('/*') == -1:
        lineMatch = False
    for l in oldLines:
        if '@' in line and line == l and 'p4port' not in line:
            lineMatch = True
            line = line.strip('\n')
            line = line.split('@')[1]
            line = line + '<br>\n'
            labels.append(line)
    if '@' in line and not lineMatch:
        line = line.strip('\n')
        line = line.split('@')[1]
        line="<font color='black' style='background:rgb(255, 215, 0)'>"+line+"</font><br>\n"
        labels.append(line)

我收到语法错误:

   if '@' in line and not lineMatch:
   UnboundLocalError: local variable 'lineMatch' referenced before assignment
关注者
0
被浏览
39
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    那“不在”呢?:

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

    另外我想你的代码可以修改为:

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


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看