답변 
 arcpy.env.workspace 경로- F:\raster_test-존재하지 않거나 arcpy에 액세스 할 수 없습니다. arcpy.ListRasters()는 빈 목록을 반환합니다. [] 래스터를 찾을 수 없지만 경로를 찾을 수없는 경우 None를 반환합니다. 
 경로가 존재합니다 : 
arcpy.env.workspace = r"C:\Temp" # Does Exist rasters = arcpy.ListRasters("*.tif) print rasters 
 출력 : 
[] 
 경로는  없음  존재 : 
arcpy.env.workspace = r"C:\Temp2" # Does NOT Exist rasters = arcpy.ListRasters("*.tif) print rasters 
 출력 : 
None 
 
 Answer 
 … 또한 코드 시작 부분에 더 가까이 백업하는 것은이 잘못된 줄입니다 (\ r은 Python에서 이스케이프 시퀀스입니다). 
arcpy.env.workspace = "F:\raster_test" # Does NOT Exist 
 제공된 F : \ raster_test가 유효한 경로 (래스터 포함)이면 제대로 작동합니다. 
arcpy.env.workspace = r"F:\raster_test" # Does Exist 
  문자열 리터럴 에 대한 Python 문서 섹션을 참조하세요. 
 댓글 
 
 답변 
 NoneType 오류, arcpy.ListRasters()는 빈 목록을 반환하고 래스터가없는 경우 NoneType를 반환하지 않습니다. 찾았습니다. 한 번 해보세요. 
import arcpy import os from arcpy.sa import ExtractByMask out_dir = r"F:\clipped_images" arcpy.env.workspace = r"F:\raster\test" arcpy.CheckOutExtension("Spatial") mask = r"F:\shapefile\Export_Output.shp" for raster in arcpy.ListRasters("*.tif"): output_raster = os.path.join(out_dir, os.path.splitext(raster)[0] + "_clip.tif") ExtractByMask(raster, mask, output_raster) arcpy.CheckInExtension("Spatial") 
 
 답변 
 다양한 List 함수 (ListTables, ListFeatureclasses 등)는 항상  지정된 작업 공간에 일치하는 유형이없는 경우 목록 변수에 대해 빠른 if 논리 테스트를 수행하세요. 
rasters = arcpy.ListRasters ("*.TIF") if rasters: your code here