여러 개의 비 파이썬 사용자가 사용할 파이썬 스크립트를 작성 중입니다. 스크립트를 실행하는 데 필요한 매개 변수가 들어있는 텍스트 파일이 있습니다.파이썬에서 사용하기위한 텍스트 파일 내의 형식 경로
입력 중 하나는 경로입니다. 스크립트를 실행시킬 수 없어서 경로를 잘못 참조했기 때문이라고 생각했습니다. 내가 시도
은 :
C:\temp\test
"C:\temp\test"
r"C:\temp\test"
C:/temp/test
"C:/temp/test"
C:\\temp\\test
"C:\\temp\\test"
나는 전화를 내 파이썬 스크립트에서 읽을 수있는 텍스트 파일에 다음 각 하나를 추가했습니다. 다른 매개 변수가 있는데 제대로 호출됩니다. 경로를 하드 코딩 할 때 스크립트가 실행되는 것 같습니다. 확인해야하는 몇 가지 버그가 있다고 생각하기 때문에 나타나는 것 같습니다.하지만 오류없이 실행됩니다. 나는 텍스트 파일을 사용하는 경우
는이 오류가 얻을 - 내가 위의 예 중 하나를 사용하는 경우에 따라 달라집니다 다음과 같이
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'c:\temp\match1\jpg\n/.'
내 코드는 다음과 같습니다에서
print ("Linking new attachments to feature")
fp = open(r"C:\temp\Match1\Match_Table.txt","r") #reads my text file with inputs
lines=fp.readlines()
InFeat = lines[1]
print (InFeat)
AttFolder = lines[3] #reads the folder from the text file
print (AttFolder)
OutTable = lines[5]
if arcpy.Exists(OutTable):
print("Table Exists")
arcpy.Delete_management(OutTable)
OutTable = lines[5]
print (OutTable)
LinkF = lines[7]
print (LinkF)
fp.close()
#adding from https://community.esri.com/thread/90280
if arcpy.Exists("in_memory\\matchtable"):
arcpy.Delete_management("in_memory\\matchtable")
print ("CK Done")
input = InFeat
inputField = "OBJECTID"
matchTable = arcpy.CreateTable_management("in_memory", "matchtable")
matchField = "MatchID"
pathField = "Filename"
print ("Table Created")
arcpy.AddField_management(matchTable, matchField, "TEXT")
arcpy.AddField_management(matchTable, pathField, "TEXT")
picFolder = r"C:\temp\match1\JPG" #hard coded in
print (picFolder)
print ("Fields added")
fields = ["MatchID", "Filename"]
cursor = arcpy.da.InsertCursor(matchTable, fields)
##go thru the picFolder of .png images to attach
for file in os.listdir(picFolder):
if str(file).find(".jpg") > -1:
pos = int(str(file).find("."))
newfile = str(file)[0:pos]
cursor.insertRow((newfile, file))
del cursor
arcpy.AddAttachments_management(input, inputField, matchTable, matchField, pathField, picFolder)
은 종종'\ n' caracter로 끝납니다. 필요 없으면 제거하는 것을 잊지 마십시오. – SRD