简体   繁体   English

在调试模式下逐步执行时没有错误,但在AttributeError情况下没有

[英]No error when stepping through in debug mode but AttributeError otherwise

Example code 范例程式码

from pathlib import Path

for f in Path(<dir>).iterdir():
    print(f._str)

I'm using it to pass to a function but not even this works when running normally or debug without a breakpoint. 我正在使用它来传递给函数,但在正常运行或没有断点的调试时甚至无法正常工作。 Using a breakpoint and stepping through it prints everything out just fine ( _str is the total path! 使用断点并逐步执行它会打印出所有内容( _str是总路径!

I'm really not sure what you are trying to do or print, but, yes, this throws an AttributeError. 我真的不确定您要做什么或打印,但是,是的,这会引发AttributeError。 Probably because, well, ._str is not an attribute of the Path class. 可能是因为._str不是Path类的属性。

from pathlib import Path

for f in Path('/tmp').iterdir():
    print(f._str)

AttributeError: _str

This does print the full path. 这不会打印完整路径。

for f in Path('/tmp').iterdir():
    print(f)

/tmp/com.apple.launchd.0CERUFd5eE
/tmp/com.apple.launchd.JLaC2VPWPS
/tmp/com.apple.launchd.jyIh6h3f8I

If you want just the names of the files & directories, do print(f.name) 如果只需要文件和目录的名称,请执行print(f.name)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python IDLE,导入 XLRD,在调试模式下产生错误:AttributeError: '_ModuleLock' object has no attribute 'name' - Python IDLE, importing XLRD, error generated in debug mode: AttributeError: '_ModuleLock' object has no attribute 'name' 单击框架内的链接可在调试模式下工作,但不能以其他方式工作 - Clicking a link inside a frame works in debug mode but not otherwise Tkinter 中的 Python function 在调试模式下工作,但不另外调用 - Python function in Tkinter works in debug mode, but does not called otherwise Python:仅当发生错误时,如何记录debug +消息,否则返回info + - Python: How to log debug+ messages only when an error occures, info+ otherwise Python在流模式下修改文件时帮助调试错误 - Python help to debug an error when modify a file in a stream mode 在运行模式下出现无效语法错误,但在调试模式下运行时正常运行 - Invalid syntax error when in run mode, but when run with debug mode it runs normally Pycharm Debug 模式语法错误 - Pycharm Debug mode syntax error 用于分析和逐步执行代码的工具? - Tool for analysing and stepping through code? 与“通过”表序列化关系时发生AttributeError - AttributeError when serializing relationship with 'through' table 为什么 Pycharm 在调试程序时显示 AttributeError: module &#39;numbers&#39; has no attribute &#39;Number&#39;,但运行它却没有发生错误? - Why does the Pycharm show AttributeError: module 'numbers' has no attribute 'Number' when I debug a program, but no error happened if I run it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM