我有一段代码在目录中创建光栅文件列表:
import arcpy, os
workspace = r'C:\temp'
# Get a list of all files in all subfolders
rasters = []
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,
topdown = True,
datatype="RasterDataset"):
for filename in filenames:
rasters.append(os.path.join(dirpath, filename))
它生成.tif文件的列表:
[r'C:\temp\block1\fileA.tif', r'C:\temp\block1\fileB.tif', r'C:\temp\block2\fileA.tif', r'C:\temp\block2\fileB.tif']
如何生成包含重复文件名的列表列表,如下面的示例?你知道吗
[[r'C:\temp\block1\fileA.tif', r'C:\temp\block2\fileA.tif'], [r'C:\temp\block1\fileB.tif', r'C:\temp\block2\fileB.tif']]
在字典中收集文件,按基名称键入;^{} object 使这更容易:
这将路径按
filename
分组到列表中;rasters.values()
构建所需的列表列表。你知道吗相关问题 更多 >
编程相关推荐