1

これらのスクリプトを変更して、エラーを無視して実行を続けることができる人はいますか? スクリプトがこれらのエラーをスキップして残りの行を終了させる方法を理解する必要があるだけです。

完全な Python スクリプトは次のとおりです。

# Import system modules
import sys, string, os, arcgisscripting

# Create the geoprocessor object
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = True

# Set the workspace. List all of the folders within
gp.Workspace = "C:\ZP4"
fcs = gp.ListWorkspaces("*","Folder")

for fc in fcs:
print fc
gp.CalculateField_management(fc + "\\Parcels.shp", "SIT_FULL_S", "myfunction(!SIT_HSE_NU!,!SIT_FULL_S!)", "PYTHON", "def myfunction(fld1,fld2):\n if (fld1=='0'or fld1=='00'or fld1<'00000000000'):\n   return ''\n else:\n   return fld2")

そして、ここに私が遭遇したエラーがあります: トレースバック (最新の呼び出しが最後):

  File "C:\Documents and Settings\Andrew\Desktop\HOUSENUMERZERO.py", line 18, in
 <module>

ERROR 000539: Error running expression: myfunction

(" ","69 FLOOD ST
") <type 'exceptions.SyntaxError'>: EOL while scanning single-quoted string (<st
ring>, line 1)

Failed to execute (CalculateField).
4

1 に答える 1

1

最初のオプション: 次のgp.CalculateField_management(...)ように、try/except でラップします。

try:
    gp.CalculateField_management(...)
except SyntaxError:
    pass

これにより、スクリプトを続行できるはずですが、状態がどうなるかはわかりませんgp

より良いオプションは、各ファイルを前処理し、改行が埋め込まれたフィールドを処理することです。何かのようなもの:

for fc in fcs:
    fix_bad_fields(fp)
    gp.Calculatate...

fix_bad_fields は次のようになります (私は .shp ファイルに慣れていないので、これを調査する必要があります。同じファイルに書き戻すことができるふりをしますが、そうでない場合は、次のようにコピーして名前を変更する必要があります。良い):

def fix_bad_fields(filename):
    data_file = open_shp_file(filename)
    for row in data_file:
        row[0] = row[0].replace('\n', '')
        row[1] = row[1].replace('\n', '')
        row1.put_changes_on_disk() # force changes to disk (may not be necessary)
    data_file.close()

これらの詳細には多くの当て推量がありますが、うまくいけば、それでアイデアが得られ、先に進むのに十分です.

于 2011-08-04T20:41:29.327 に答える