Select to view content in your preferred language

EOL calculating field, single quoted - scrubbing addresses

1826
4
05-10-2011 08:35 AM
TurnerNowak
Deactivated User
Would anyone be able to point me in the right direction ?  I need to figure out how to either make the script ignore these errors and continue to run, or actually be able to handle these lines that currently shut down the script.




C:\ZP4>call housenumberzero.bat

C:\ZP4>C:\Python24\HOUSENUMERZERO.py
C:\ZP4\49003
C:\ZP4\49053
Traceback (most recent call last):
  File "C:\Python24\HOUSENUMERZERO.py", line 21, in <module>
    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")
arcgisscripting.ExecuteError: ERROR 000539: Error running expression: myfunction("69","69 FLOOD ST

") <type 'exceptions.SyntaxError'>: EOL while scanning single-quoted string (<string>, line 1)
Failed to execute (CalculateField).


C:\ZP4>call 1LowerCaseSitusFull.bat

C:\ZP4>C:\Python24\SITUSLOWERPYTON.py
C:\ZP4\49003
C:\ZP4\49053
Traceback (most recent call last):
  File "C:\Python24\SITUSLOWERPYTON.py", line 17, in <module>
    gp.CalculateField_management(fc + "\\Parcels.shp", "SIT_FULL_S", "!SIT_FULL_S!.title()", "PYTHON", "")
arcgisscripting.ExecuteError: ERROR 000539: Error running expression: "69 FLOOD ST

".title() <type 'exceptions.SyntaxError'>: EOL while scanning single-quoted string (<string>, line 1)
Failed to execute (CalculateField).
Tags (2)
0 Kudos
4 Replies
JasonScheirer
Esri Alum
Try this:


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")
0 Kudos
TurnerNowak
Deactivated User
Thanks, I tried that and here is what I got:

C:\ZP44\49053 situs batch errors
Traceback (most recent call last):
  File "C:\Documents and Settings\Andrew\Desktop\Copy of HOUSENUMERZERO.py", lin
e 18, in <module>
    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 f
ld2")
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000989: Python syntax error: Parsing error <type 'exceptions.IndentationEr
ror'>: expected an indented block (line 3)
Failed to execute (CalculateField).
0 Kudos
JasonScheirer
Esri Alum
Missing indentation in your function block's return statements:

"def myfunction(fld1,fld2):\n if (fld1=='0'or fld1=='00'or fld1<'00000000000'):\n   return ''\n else:\n   return fld2"
0 Kudos
TurnerNowak
Deactivated User
Missing indentation in your function block's return statements:

"def myfunction(fld1,fld2):\n if (fld1=='0'or fld1=='00'or fld1<'00000000000'):\n   return ''\n else:\n   return fld2"


Thanks, I tried the above indentation but got this error:

Traceback (most recent call last):

  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).
0 Kudos