最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - When debugging with Pycharm, code that should not have been executed was executed - Stack Overflow

programmeradmin0浏览0评论

When I was debugging Python code with Pycharm, I encountered a strange problem where a function that should not have been executed was executed. Here is my code:

import os

input_dir = "D:/MyCode/Data/t"

for root, dirs, files in os.walk(input_dir):
    for file in files:
        if file.endswith(".jpg") and '-' in file:
            if file == "x":
                print("error")

I don't have the file x in my folder, but when I set a breakpoint in the print ("error") code, print ("error") executes and outputs an error. If I set breakpoints at if file. endscan (". jpg") and '-' in file:, print ("error") will not be executed, and when I run the code without debugging, print ("error") will not be executed either. May I ask what caused this?

Location of breakpoint setting

results of execution

This is a reproduced image of my problem. I set a breakpoint at the print function, but the print function that should not have been executed was executed instead, and the program did not exit properly

I tried to change the files in the folder, but even if there were no files in my folder, the print function would still be executed.

Sorry, I may not have explained my question clearly. What I mean is that in my code logic, if file == "x": should never be true, so print("error") should not be executed. However, during breakpoint debugging, when I place a breakpoint at print("error"), the console outputs "error" and the program exits with exit code -1073741819 (0xC0000005). What could be the reason for this?

I changed the output to file, mask.png is clearly not equal to x, but the console still outputs mask.png.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论