admin管理员组文章数量:1431400
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.
本文标签:
版权声明:本文标题:python - When debugging with Pycharm, code that should not have been executed was executed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745572592a2664136.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论