複数の非Pythonユーザーが使用するためのPythonスクリプトを作成しています。 私のスクリプトが実行する必要があるパラメータを含むテキストファイルがあります。Pythonで使用するためのテキストファイル内の書式パス
入力の1つがパスです。私のスクリプトを実行することができないと私は誤って私のパスを参照していたためだと思っていた。
私が試してみました:
C:\temp\test
"C:\temp\test"
r"C:\temp\test"
C:/temp/test
"C:/temp/test"
C:\\temp\\test
"C:\\temp\\test"
私はPythonスクリプトで呼び出され、読み込まれたテキストファイルの中にこれらの各1を追加しました。 私は他のパラメータを持っていて、正しく呼び出されているので、パスをハードコードするとスクリプトが実行されているようです。私はチェックする必要のあるバグがいくつかあると考えているようです。
私はこのエラーを取得テキストファイルを使用する場合 - 私は上記の例のいずれかを使用した場合によって異なります。
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