<?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: Field Calculation: ERROR 000539 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29017#M2238</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I start an edit session and put my cursor in the parcel record ending in 062, then use the arrow keys to arrow right, the value disappears.&amp;nbsp; I'm guessing this is why I should be trying to replace the \n values?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Nov 2012 16:45:27 GMT</pubDate>
    <dc:creator>LeoDonahue</dc:creator>
    <dc:date>2012-11-08T16:45:27Z</dc:date>
    <item>
      <title>Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29010#M2231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have been trying to do a field calculation in ArcMap 10.0 sp5 and PYTHON_9.3 expression type, with not much success.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The field I am trying to calculate is a Text field with a length of 50, even though the data in that field "should" never have a length longer than 12 (it's not my data), it's just the way that field was created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
Start Time: Thu Nov 01 10:13:08 2012
ERROR 000539: &amp;lt;type 'exceptions.SyntaxError'&amp;gt;: EOL while scanning string literal (&amp;lt;expression&amp;gt;, line 1)
Failed to execute (Calculate Field).
Failed at Thu Nov 01 10:18:15 2012 (Elapsed Time: 5 minutes 7 seconds)
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are some feature attribute values in the field that have some kind of padding applied to them which is causing this error - I believe.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;.strip() is not removing the whitespace, as the script will process about 80% of the records before it hits the one record causing the problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anyone tell what I'm missing?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 16:29:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29010#M2231</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2012-11-01T16:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29011#M2232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Check if are there any "\" characters in the string (like \n, \t). If so, replace them with "//" first.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 18:44:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29011#M2232</guid>
      <dc:creator>klem</dc:creator>
      <dc:date>2012-11-01T18:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29012#M2233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It could be null values that are throwing it off.&amp;nbsp; For 'Expression' change it to &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
setAPN2(str(!PG_APN!).strip())
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will convert any null values to a string representation of 'None'.&amp;nbsp; Then alter your function like below&amp;nbsp; Even if this isn't what is causing your specific error, this is good practice to ensure against null values breaking your code.&amp;nbsp; You would then need to alter your function as below to only work on non-null values.&amp;nbsp; Also, you can wrap the whole thing in try and except blocks to analyze which values aren't calculating and why.&amp;nbsp; If none of the records get calculated, it's probably an error in the logic.&amp;nbsp; Can you post a screenshot of some of the sample record values in the PG_APN field?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def setAPN2(parcel):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if parcel != 'None':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue = parcel[0:3] + '-' + parcel[3:5] + '-'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(parcel) &amp;lt;= 8:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[-3:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[-1:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return strValue
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execept:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:09:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29012#M2233</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2021-12-10T21:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29013#M2234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oops...missed part of the logic for parcel strings with length &amp;gt; 8.&amp;nbsp; Also added a calculation of error records to 'Error - Unable to calculate' &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def setAPN2(parcel):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if parcel != 'None':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue = parcel[0:3] + '-' + parcel[3:5] + '-'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(parcel) &amp;lt;= 8:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[-3:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[5:8] + '-' + parcel[-1:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execept:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue = 'Error - unable to calculate'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return strValue
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:10:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29013#M2234</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2021-12-10T21:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29014#M2235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Actually.....looking at the code and the error, i'm pretty sure what is wrong.&amp;nbsp; It is trying to strip the field name argument itself, which isn't a string.&amp;nbsp; That's why you're getting the scanning string literal error.&amp;nbsp; Try the solution below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
setAPN2(str(!PG_APN!))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then alter the function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def setAPN2(parcel):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if parcel != 'None':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parcel = parcel.strip()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue = parcel[0:3] + '-' + parcel[3:5] + '-'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(parcel) &amp;lt;= 8:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[-3:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[5:8] + '-' + parcel[-1:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue = 'Error - unable to calculate'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return strValue
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:10:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29014#M2235</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2021-12-10T21:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29015#M2236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Bruce, Krzysztof,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the tips.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't visually see a \n character in any of the values.&amp;nbsp; Does that mean it might be there anyway?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still getting this error when I run the following code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]19106[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 13:48:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29015#M2236</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2012-11-07T13:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29016#M2237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's really weird.&amp;nbsp; I see no clear difference between records 959777 and 959778 that would cause one to calculate and the other to error out.&amp;nbsp; I would highly recommend the try and except blocks.&amp;nbsp; The calculation won't ever completely error out...if it can't perform the operation, it will default to 'Unable to calculate'.&amp;nbsp; This will allow you to analyze what is different about those records that aren't calculated.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def setAPN2(parcel):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parcel = parcel.strip()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue = parcel[0:3] + '-' + parcel[3:5] + '-'&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(parcel) &amp;lt;= 8:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[5:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue += parcel[5:8] + '-' + parcel[8:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strValue = 'Unable to calculate'
&amp;nbsp;&amp;nbsp;&amp;nbsp; return strValue
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:10:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29016#M2237</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2021-12-10T21:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29017#M2238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I start an edit session and put my cursor in the parcel record ending in 062, then use the arrow keys to arrow right, the value disappears.&amp;nbsp; I'm guessing this is why I should be trying to replace the \n values?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Nov 2012 16:45:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29017#M2238</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2012-11-08T16:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation: ERROR 000539</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29018#M2239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Leo,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;you are probably right, there is "new line" (\n) or tab (\t) character, so first you should clean this field or add&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;parcel = parcel.replace("\n","")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;parcel = parcel.replace("\t","")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lines to your code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Nov 2012 17:39:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-error-000539/m-p/29018#M2239</guid>
      <dc:creator>klem</dc:creator>
      <dc:date>2012-11-08T17:39:21Z</dc:date>
    </item>
  </channel>
</rss>

