简体   繁体   English

glob.glob结果不一致

[英]Inconsistent glob.glob results

Can anyone tell me why this command works: 谁能告诉我此命令为何起作用:

lefs = glob.glob(".\lef\*.lef")

but this doesnt? 但这不是吗?

techFiles = glob.glob(".\techfile\*.tcl")

I have to add the extra backslash in order for it to work: 我必须添加额外的反斜杠以使其正常工作:

techFiles = glob.glob(".\\techfile\*.tcl")

The other line works fine with no extra backslash.. These are just simple files with different extensions. 另一行工作正常,没有多余的反斜杠。.这些只是具有不同扩展名的简单文件。

All files exists and are in the correct directory. 所有文件都存在并且位于正确的目录中。

in techFiles = glob.glob(".\\techfile\\*.tcl") , \\t is interpreted as a tabulation char (other "problematic chars are \\b , \\v , \\a , \\x , \\b , \\f , \\U , \\ followed by a digit, ... I may forget some) techFiles = glob.glob(".\\techfile\\*.tcl")\\t被解释为制表techFiles = glob.glob(".\\techfile\\*.tcl") (其他“有问题的字符为\\b\\v\\a\\x\\b\\f\\U\\后跟一个数字,...我可能会忘记一些)

So the path is invalid and glob.glob returns nothing. 因此该路径无效,并且glob.glob返回任何内容。

Your other path contains \\l and \\* which doesn't correspond to any escape sequence, so it is not interpreted and kind of works. 您的其他路径包含\\l\\* ,它们不与任何转义序列相对应,因此不会被解释并且无法正常工作。

To pass string literals as Windows paths, always use raw prefix, it's simpler than escaping each backslash: 要将字符串文字作为Windows路径传递,请始终使用原始前缀,这比转义每个反斜杠更简单:

techFiles = glob.glob(r".\techfile\*.tcl")

Slightly off-topic: there's a lot of code examples here with capitalized directory names: ex glob.glob(".\\Techfile\\Backlog\\*.tcl") , and I always wondered if it was mere luck, or if most people still don't get this \\t issue and find a workaround by capitalizing, since Windows paths are case-insensitive... glob.glob(".\\Techfile\\Backlog\\*.tcl")题外话:这里有很多用大写目录名的代码示例:ex glob.glob(".\\Techfile\\Backlog\\*.tcl") ,我一直想知道这是否只是运气,还是大多数人仍然因为Windows路径不区分大小写,所以不要遇到这个\\t问题并通过大写找到解决方法...

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM