[英]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.