<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: EOL errors when performed simple task in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589144#M46154</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jason, this does not work if the string has an embedded newline. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[indent]&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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 (&amp;lt;expression&amp;gt;, line 1)
Failed to execute (CalculateField).
Failed at Thu Sep 12 10:59:13 2013 (Elapsed Time: 0.00 seconds)
&lt;/PRE&gt;&lt;SPAN&gt;[/indent]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Iggz, first of all, remind your user that although Excel is a great analysis environment, &lt;/SPAN&gt;&lt;STRONG&gt;it is an absolutely terrible database. &lt;/STRONG&gt;&lt;SPAN&gt;(This is gospel I have been preaching to fellow researchers for decades with very limited success!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;More info on this issue here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[thread=50738]End-of-line (EOL) Problem [/thread]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"""!TEXTFIELD!""".strip()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def striptext(tbl, fld):
&amp;nbsp; Rows = arcpy.da.UpdateCursor(tbl, fld)
&amp;nbsp; for Row in Rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Row[0] = Row[0].strip()
&amp;nbsp;&amp;nbsp;&amp;nbsp; Rows.updateRow(Row)

# Then, call the function like this:
striptext("mytable","TEXTFIELD")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27402[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:39:57 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-12T16:39:57Z</dc:date>
    <item>
      <title>EOL errors when performed simple task</title>
      <link>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589142#M46152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a field that lists numbers in the following format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;"000000-000"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But when this data was inputted, the user just copied and pasted the value from an excel sheet into the program and this caused a carriage return to be inputted with the value above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;"000000-000 "&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I haven't been able to fix this problem with Python, but I can with VB which seems a bit backwards to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why is Python so limited within ArcMap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To fix this I tried multiple ways in Python, but they all failed even though they were valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The only way I was able to fix it was by using VB to get the length of the field for each record. So the field length should be 10 (123456-890). But with the carriage return the length for these fields returned 11, so I am able to isolate them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I figured, hey I'll use Python now. So I wrote the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def alterField(field): &amp;nbsp;&amp;nbsp;&amp;nbsp; a = field[0:10] &amp;nbsp;&amp;nbsp;&amp;nbsp; return a&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And this simple function fails in ArcMap with an EOL error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What gives? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ended up having to use the VB Left() function to fix it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Python is so powerful, but so limited by ArcMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why is this and will this ever be fixed?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 13:57:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589142#M46152</guid>
      <dc:creator>IB1</dc:creator>
      <dc:date>2013-09-12T13:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: EOL errors when performed simple task</title>
      <link>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589143#M46153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You just need to use &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;string.strip()&lt;/SPAN&gt;&lt;SPAN&gt;. Just use &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;!field!.strip()&lt;/SPAN&gt;&lt;SPAN&gt; 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.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 15:33:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589143#M46153</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-09-12T15:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: EOL errors when performed simple task</title>
      <link>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589144#M46154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jason, this does not work if the string has an embedded newline. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[indent]&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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 (&amp;lt;expression&amp;gt;, line 1)
Failed to execute (CalculateField).
Failed at Thu Sep 12 10:59:13 2013 (Elapsed Time: 0.00 seconds)
&lt;/PRE&gt;&lt;SPAN&gt;[/indent]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Iggz, first of all, remind your user that although Excel is a great analysis environment, &lt;/SPAN&gt;&lt;STRONG&gt;it is an absolutely terrible database. &lt;/STRONG&gt;&lt;SPAN&gt;(This is gospel I have been preaching to fellow researchers for decades with very limited success!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;More info on this issue here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[thread=50738]End-of-line (EOL) Problem [/thread]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"""!TEXTFIELD!""".strip()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def striptext(tbl, fld):
&amp;nbsp; Rows = arcpy.da.UpdateCursor(tbl, fld)
&amp;nbsp; for Row in Rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Row[0] = Row[0].strip()
&amp;nbsp;&amp;nbsp;&amp;nbsp; Rows.updateRow(Row)

# Then, call the function like this:
striptext("mytable","TEXTFIELD")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27402[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:39:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589144#M46154</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T16:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: EOL errors when performed simple task</title>
      <link>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589145#M46155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You just need to use &lt;SPAN style="font-family:Courier New;"&gt;string.strip()&lt;/SPAN&gt;. Just use &lt;SPAN style="font-family:Courier New;"&gt;!field!.strip()&lt;/SPAN&gt; 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.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh I know Python very well. Maybe you should try what you're preaching because that DEFINITELY doesn't work with return carriages in the data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Trust me, I tried it. It still gives the EOL error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does it work outside of ArcMap? Sure does. I call that limitations.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 15:59:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589145#M46155</guid>
      <dc:creator>IB1</dc:creator>
      <dc:date>2013-09-12T15:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: EOL errors when performed simple task</title>
      <link>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589146#M46156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Jason, this does not work if the string has an embedded newline. &lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot for the helpful answer, I'll try it next time.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 16:12:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589146#M46156</guid>
      <dc:creator>IB1</dc:creator>
      <dc:date>2013-09-12T16:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: EOL errors when performed simple task</title>
      <link>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589147#M46157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;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.)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for posting Curtis!!!!&amp;nbsp; I was struggling with this for a while...I did not think to use chr()...I was having issues passing newlines into advanced python label expressions and banging my head against the wall trying to figure out where I was going wrong.&amp;nbsp; This seems to be a nice workaround.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 17:13:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/eol-errors-when-performed-simple-task/m-p/589147#M46157</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-09-12T17:13:50Z</dc:date>
    </item>
  </channel>
</rss>

