参数有关的的问题

gistop 2013-10-08 12:08:10
如下代码,其他不要看,也不需要理解,就看红色有下划线部分。这个是写死的针对特定某个文件的处理。但我遍历文件夹里面的文件,通过for循环,文件是变化的,在红色部分,文件名split_101路_大连火车站_马栏广场_.shp 怎么用文件名stopname来表示,而不是写死。多谢指点,头有些晕。

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# py.py
# Created on: 2013-10-07 10:06:26.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Set the necessary product code
# import arcinfo


# Import arcpy module
import arcpy
import os
import os.path


# Local variables:
a = ""
b = ""
c = ""
templine = ""
tempstop = ""
for file in os.listdir("c:/workspace/splits"):
if file.endswith('.shp'):
templine = file
a = "C:\\workspace\\splits\\" + file
temp = a.split('_')

linename = temp[1] + "_" + temp[2] + "_" + temp[3]
stopname = "stop_" + linename + "_.shp"



for f in os.listdir("c:/workspace/stops"):
tempstop = f
b = "C:\\workspace\\stops\\" + stopname
if os.path.isfile(b):
resultname = "join_" + linename + "_.shp"
c = "C:\\workspace\\joinlines\\" + resultname
if os.path.isfile(c):
print "exist"
break
else:
arcpy.SpatialJoin_analysis(a, b, c, "JOIN_ONE_TO_ONE", "KEEP_ALL", "OBJECTID \"OBJECTID\" true true false 9 Long 0 9 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,OBJECTID,-1,-1;startTime \"startTime\" true true false 50 Text 0 0 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,startTime,-1,-1;endTime \"endTime\" true true false 50 Text 0 0 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,endTime,-1,-1;stopsCount \"stopsCount\" true true false 4 Short 0 4 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,stopsCount,-1,-1;SHAPE_Leng \"SHAPE_Leng\" true true false 19 Double 0 0 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,SHAPE_Leng,-1,-1;direction \"direction\" true true false 50 Text 0 0 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,direction,-1,-1;linename \"linename\" true true false 100 Text 0 0 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,linename,-1,-1;lineco \"lineco\" true true false 100 Text 0 0 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,lineco,-1,-1;OBJECTID_1 \"OBJECTID_1\" true true false 9 Long 0 9 ,First,#,C:\\workspace\\stops\\stop_101路_大连火车站_马栏广场_.shp,OBJECTID,-1,-1;name \"name\" true true false 50 Text 0 0 ,First,#,C:\\workspace\\stops\\stop_101路_大连火车站_马栏广场_.shp,name,-1,-1;ofline \"ofline\" true true false 100 Text 0 0 ,First,#,C:\\workspace\\stops\\stop_101路_大连火车站_马栏广场_.shp,ofline,-1,-1;id \"id\" true true false 4 Short 0 4 ,First,#,C:\\workspace\\stops\\stop_101路_大连火车站_马栏广场_.shp,id,-1,-1", "INTERSECT", "100 Meters", "")
break
...全文
124 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gistop 2013-10-08
  • 打赏
  • 举报
回复
关键我想不通的地方在于,这个函数里面的其他如 "KEEP_ALL",这是个字符串,用个for循环赋值的变量替换就行。而这个参数 C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp 这么写,算是个什么?我怎么用个变量来替换? 多谢指点。
ImN1 2013-10-08
  • 打赏
  • 举报
回复
>>> a="split_101路_大连火车站_马栏广场_.shp"
>>> str="OBJECTID \"OBJECTID\" true true false 9 Long 0 9 ,First,#,C:\\workspace\\splits\\%s,……"
>>> s=str % a
>>> s
'OBJECTID "OBJECTID" true true false 9 Long 0 9 ,First,#,C:\\workspace\\splits\\split_101路_大连火车站_马栏广场_.shp,……'
看得明白么?省略号的部分你自己补充吧
crifan 2013-10-08
  • 打赏
  • 举报
回复
你还是重新发一下你的代码。 注意用code括起来,否则太乱,反正我是懒得看太乱的代码。
ChongQingJin28 2013-10-08
  • 打赏
  • 举报
回复
format

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧