我有一个相当简单的 python 循环,它调用一些函数,并将输出写入文件。为此,创建一个文件夹,并将文件保存在此文件夹中。
当我第一次使用唯一的文件名运行程序时,它运行良好。但是,如果我再次尝试运行它,它将无法正常工作,我不明白为什么。我很确定这不是覆盖文件的问题,因为我在重新运行之前删除了文件夹,这是唯一存储文件的地方。有没有我误解的概念?
有问题的文件是“buff1.shp”。我正在使用 Python 2.5 在 ArcGIS 中运行一些分析
感谢您提供任何建议(包括有关如何改进我的编码风格的建议)。另一个注意事项是我的循环目前只使用一个值,因为我目前正在测试它。
# Import system modules
import sys, string, os, arcgisscripting, shutil
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Statistics Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
# specify workspace
gp.Workspace = "C:/LEED/Cities_20_Oct/services"
path = "C:\\LEED\\Cities_20_Oct\\services\\"
results = 'results\\'
os.mkdir( path + results )
newpath = path + results
# Loop through each file (0 -> 20)
for j in range(0,1):
in_file = "ser" + str(j) + ".shp"
in_file_2 = "ser" + str(j) + "_c.shp"
print "Analyzing " + str(in_file) + " and " + str(in_file_2)
#Loop through a range of buffers - in this case, 1,2
for i in range(1,2):
print "Buffering....."
# Local variables...
center_services = in_file_2
buffer_shp = newpath + "buff" + str(i) + ".shp"
points = in_file_2
buffered_analysis_count_shp = newpath + "buffered_analysis_count.shp"
count_txt = newpath + "count.txt"
# Buffer size
b_size = 1000 + 1000 * i
b_size_input = str(b_size) + ' METERS'
print "Buffer:" + b_size_input + "\n"
# Process: Buffer...
gp.Buffer_analysis(center_services, buffer_shp, b_size_input, "FULL", "ROUND", "ALL", "")
print "over"
(为了澄清这个问题,我编辑了一些没有其余代码就没有意义的部分。错误仍然存在于程序中。)
错误信息:
ExecuteError: ERROR 000210: Cannot create output C:\LEED\Cities_20_Oct\services\results\buff1.shp Failed to execute (Buffer).