Python新手。
我目前正在尝试比较对目录中的文件执行glob.glob方法的返回值,但是在理解如何比较未知列表中每个元素末尾的第6个字符时遇到了障碍。
例如Output = glob.glob('Report1.0REV_*.xlsx')
的输出
会回来
['Report1.0REV_A.xlsx', 'Report1.0REV_B.xlsx', 'Report1.0REV_C.xlsx', etc]
但是我如何比较如果我附加每个文件以获得A> B或C> B,或X> Y,然后打印最新文件?
到目前为止,可以想到的是编写一个带有列表长度的for循环,但仍然理解我如何比较列表中每个元素的-6字符更大,然后打印该文件。
for i in range(len(Output)):
感谢您的阅读和帮助!
答案 0 :(得分:0)
如果我理解你的答案,你想在排序列表后获取最后一个文件名。如果是这种情况,那么以下代码可能会对您有所帮助。如你所说,你是Python的新手,我添加了大量可能有帮助的评论:
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch localhost",
"type": "chrome",
"request": "launch",
"url": "http://localhost/some_name",
"webRoot": "${workspaceRoot}/wwwroot"
},
{
"name": "Launch index.html (disable sourcemaps)",
"type": "chrome",
"request": "launch",
"sourceMaps": false,
"file": "${workspaceRoot}/index.html"
},
]
}