Jason, this does not work if the string has an embedded newline. [indent]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]Iggz, first of all, remind your user that although Excel is a great analysis environment, it is an absolutely terrible database. (This is gospel I have been preaching to fellow researchers for decades with very limited success!)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.) I'm willing to live with this -- because there are viable workarounds and I figure this limitation is a cost of the simplicity of having geoprocessing tools easily convert to services, and the easy similar interface tools in ModelBuilder, command line, and scripting.More info on this issue here:[thread=50738]End-of-line (EOL) Problem [/thread]Generally, I have found that VBScript is less picky about its syntax, but I prefer Python's lack of ambiguity and awesome elegance, and its closer integration with ArcGIS.Always hopeful, I tried this expression with Calculate Field with no luck, the expression string is getting garbled before it gets to the Python parser and you get the dreaded EOL error."""!TEXTFIELD!""".strip()
The only workaround I think is to apply this python function to your data (from the python command window, a python script, or the Calculate Value tool (this flavor of cursor is for 10.1 or later, you'll need to refactor this for pre-10.1):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")
[ATTACH=CONFIG]27402[/ATTACH]