"000000-000"
"000000-000 "
def alterField(field): a = field[0:10] return a
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)
"""!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")
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.)
Jason, this does not work if the string has an embedded newline. ......
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.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.