python为什么会存在if执行了依然会执行elif的情况?

发布于 2022-09-11 18:50:58 字数 1781 浏览 15 评论 0

如题,是在一个案例的for循环中,if执行了,按理elif不应该执行,但是结果依然执行了elif,不太理解,是忽略了什么吗

for msg in track:
    print '-----------------------------------------------------'
    print "the msg is {} \n".format(msg)
    print '\n'

    if isinstance(msg, midi.EndOfTrackEvent):
        print "end of track!!pass!!"
        continue
        
    if msg.tick > 0:
        print '##msg.tick > 0 !!!'
        current_tick += msg.tick
        print 'current_tick plus {} tick!'.format(msg.tick)
        print current_tick
        print msg.tick
    if isinstance(msg, midi.NoteOnEvent) and msg.get_velocity() != 0:
        if len(notes[msg.get_pitch()]) > 0 and len(notes[msg.get_pitch()][-1]) != 2:
            if verbose:
                print("double NoteOn encountered,delete the first")
                print "the msg double note_on msg is {} \n".format(msg)
                print "the pitch is {}".format(msg.get_pitch())
        else:
            notes[msg.get_pitch()] += [[current_tick]]
            print notes[msg.get_pitch()]
            print [[current_tick]]
            print '#####this is noteonevent,,,the current_tick plus {} #####\n'.format(msg.get_pitch)
            # print 'the cu'
    elif isinstance(msg, midi.NoteOffEvent) or (isinstance(msg, midi.NoteOnEvent) and msg.get_velocity() == 0):
        if len(notes[msg.get_pitch()][-1]) != 1:
            if verbose:
                print ("warning:skipping noteoff event with no corresponding noteon")
                print (msg)
        else:
            notes[msg.get_pitch()][-1] += [current_tick]
            print "the current_tick plus {} \n".format(notes[msg.get_pitch()][-1])
            print notes[msg.get_pitch()][-1]
            print [current_tick]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奈何桥上唱咆哮 2022-09-18 18:50:58

不存在单次进入if和elif分支的,只有一种可能就是你看错了。

挥剑断情 2022-09-18 18:50:58

我猜测与前面多个同层的if有关系,如果只想前一个if为true不要执行elif,那就干脆改成else试一试。

或者改动一下结构, 实在没必要连续几个if同层

↙温凉少女 2022-09-18 18:50:58

1、你忽略了要贴代码
2、你要相信,一般bug不是语言造成的,而是写代码的人~~~

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文