import os
folderpath = "C:\Users\Michaelf\Desktop\GEOG M173\LabData"
filelist = os.listdir(folderpath)
print filelist
Counter_Shapefiles = 0
Names_of_Shapefiles = 0
for the_file_name in filelist:
File_Extension = the_file_name[-4:]
if "file_Extension == .shp":
Counter_Shapefiles= Counter_Shapefiles + 1
Names_of_Shapefiles.append
答案 0 :(得分:0)
Names_of_Shapefiles是一个int。将其更改为列表并将要添加的内容添加到追加调用中。
此外,在添加问题时,请注意您获得的错误以供将来参考。
答案 1 :(得分:0)
import os
folderpath = "C:\Users\Michaelf\Desktop\GEOG M173\LabData"
filelist = os.listdir(folderpath)
print filelist
Counter_Shapefiles = 0
Name_of_Shapefiles = []
for the_file_name in filelist:
File_Extension = the_file_name[-4:]
if File_Extension == ".shp":
Counter_Shapefiles = Counter_Shapefiles+1
Names_of_Shapefiles.append(the_file_name)
查看我对您的代码所做的更改。
答案 2 :(得分:0)
使用追加你需要一个列表而不是一个int
Name_of_Shapefiles = 0
应该是
Name_of_Shapefiles = []
其次,追加的语法是Names_of_Shapefiles.append(the_file_name)