首页 > 解决方案 > 简单的 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)

标签: pythonglob

解决方案


您已经在导入 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)

推荐阅读