我是python的新手。我有这段代码:
import arcpy
from arcpy import env
import os
from arcpy.sa import *
# Set the current workspace
env.workspace = "\C:\Users\kfi179\Desktop\rgccsdaily2013"
outWorkspace = "C:\Users\kfi179\Desktop\Texas)"
dataType = "FLOAT"
#Check out the Arcgis Spatial Anaylst extension licence
arcpy.CheckOutExtension("Spatial")
# Get a list of ascii
for file in arcpy.ListFiles("*.txt"):
#Print raster list
print file
outputraster = file[0:12] + ".tif"
#Save TIF
#outRaster.save(output)
arcpy.ASCIIToRaster_conversion(file,outputraster,dataType)
并不断收到此错误:
Traceback (most recent call last):
File "C:\Users\kfi179\Desktop\AsciiToRaster.py", line 17, in <module>
for file in arcpy.ListFiles("*.txt"):
TypeError: 'NoneType' object is not iterable
我需要做些什么来解决它?
谢谢!
答案 0 :(得分:2)
似乎arcpy.ListFiles("*.txt")
返回None而不是文件列表。我注意到你的env设置为"\C:\Users\kfi179\Desktop\rgccsdaily2013"
。我认为你在开头有一个反斜杠,使文件列表失败。此外,需要转义反斜杠。可能更好地使用正斜杠
"C:/Users/kfi179/Desktop/rgccsdaily2013"