"000000-000"
"000000-000 "
def alterField(field): a = field[0:10] return a
Solved! Go to Solution.
Executing: CalculateField "table_test" TEXTFLD !TEXTFLD!.strip() PYTHON_9.3 # Start Time: Thu Sep 12 10:59:13 2013 ERROR 000539: SyntaxError: EOL while scanning string literal (<expression>, line 1) Failed to execute (CalculateField). Failed at Thu Sep 12 10:59:13 2013 (Elapsed Time: 0.00 seconds)[/indent]
"""!TEXTFIELD!""".strip()
def striptext(tbl, fld): Rows = arcpy.da.UpdateCursor(tbl, fld) for Row in Rows: Row[0] = Row[0].strip() Rows.updateRow(Row) # Then, call the function like this: striptext("mytable","TEXTFIELD")
Executing: CalculateField "table_test" TEXTFLD !TEXTFLD!.strip() PYTHON_9.3 # Start Time: Thu Sep 12 10:59:13 2013 ERROR 000539: SyntaxError: EOL while scanning string literal (<expression>, line 1) Failed to execute (CalculateField). Failed at Thu Sep 12 10:59:13 2013 (Elapsed Time: 0.00 seconds)[/indent]
"""!TEXTFIELD!""".strip()
def striptext(tbl, fld): Rows = arcpy.da.UpdateCursor(tbl, fld) for Row in Rows: Row[0] = Row[0].strip() Rows.updateRow(Row) # Then, call the function like this: striptext("mytable","TEXTFIELD")
You just need to use string.strip(). Just use !field!.strip() as your expression in the field calculator as Python. ArcGIS does nothing to limit the capabilities of the Python language, it's just a matter of learning it.
Jason, this does not work if the string has an embedded newline.
......
The limitation you've run into isn't with Python but with the geoprocessing environment's inability to easily pass newlines around in arguments, even when escaped. (For example, in a Calculate Value code block you cannot include "\n" in your code, you need to use the chr() function to insert newlines in strings.)