python - 在 while 循环内使用 try finally 时 PyCharm IDE 无法访问代码

标签 python pycharm

以下代码导致 PyCharm 将最后一行检测为“无法访问的代码”,尽管它是完全可访问的。

import random

def test_func():
    while True:
        print("start")
        try:
            if random.random() > 0.5:
                break
        finally:
            print("Finally")
    print("Done")

if __name__ == '__main__':
    test_func()

当不包含try/finally block 时,不会发生错误。

这是相关的屏幕截图:

PyCharm showing print("Done") as unreachable

最佳答案

该问题已报告 herehere它应该在 PyCharm 2016.3 中修复。

关于python - 在 while 循环内使用 try finally 时 PyCharm IDE 无法访问代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41421487/

相关文章:

python - 如何获取更新时的最后一行 ID?

intellij-idea - 如何修复 IntelliJ 14.1 中被截断的文本底部?

python - 自动完成并不总是适用于 Pycharm

refactoring - Shift+F6重构时如何跳过预览窗口

Python gRPC 服务器未启动

python - 在 tensorflow 中对不平衡数据集进行二次采样

python - 拖放图像并在网格布局上显示图像 - Kivy

python - 错误: no module named gtk.林间空地

python-2.7 - numpy.distutils.system_info.NotFoundError : no lapack/blas resources found

python - “机器人未被识别为内部或外部命令”