python - 简单的 glob 命令在打印语句中不返回任何内容
问题描述
我有这段代码可以返回我感兴趣的文件的路径列表。但是,当我在 putty 中运行这段代码时,没有返回任何打印语句;在命令行上没有任何反应。
我知道提供的路径应该返回一个输出,就像在命令行上成功使用它一样。
这是代码:
from glob import glob
#using glob package to find files for models
file_list = glob.glob('/soge-home/data/model/cmip6/CMIP6/CMIP/*/*/historical/r1i1p1f1/Amon/pr/gn/latest/*.nc', recursive=True)
file_list.sort()
#printing file names
for ifile in file_list:
print(ifile)
解决方案
您已经在导入 glob.glob。不要调用 glob.glob(),而是使用 glob()
from glob import glob
#using glob package to find files for models
file_list = glob('/soge-home/data/model/cmip6/CMIP6/CMIP/*/*/historical/r1i1p1f1/Amon/pr/gn/latest/*.nc', recursive=True)
file_list.sort()
#printing file names
for ifile in file_list:
print(ifile)
推荐阅读
- c# - Linq-to-SQL 谓词 VS UNION
- c - 结构外的指针和结构内的指针指向同一个数组并具有不同的存储地址
- python - 如果需要,列表理解中的索引问题
- http - 使用http post方法flutter时出错
- c++ - reinterpret_cast 意外地将类型从 `const float *` 更改为 `float`
- react-native - 如何在 mac 上卸载 react-native-cli?
- android - 是否可以同时使用 MIC、CAMCORDER 和加速度计进行录制?
- excel - 如何以编程方式在 Excel VBA 中移动或调整验证消息框的大小
- ldap - Spring Data LDAP 通常用于绑定身份验证吗?
- reactjs - 如何通过故事书传递我的组件主题?