<?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: Using code block with Field Calculator error 000539 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1123337#M63162</link>
    <description>&lt;P&gt;Hi, Ben (just in case you haven't already tried this) you may want to try pasting it in from notepad ++ again and just saving out a new .cal file, when I did this I no longer had issues, which made me think perhaps I unknowingly introduced something into the .cal file one time or saved it incorrectly, worth a shot if you haven't already tried. Seems to have worked for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Luke&lt;/P&gt;</description>
    <pubDate>Tue, 07 Dec 2021 14:39:45 GMT</pubDate>
    <dc:creator>LukeAllen2</dc:creator>
    <dc:date>2021-12-07T14:39:45Z</dc:date>
    <item>
      <title>Using code block with Field Calculator error 000539</title>
      <link>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1097447#M62356</link>
      <description>&lt;P&gt;Using ArcMap 10.8.1&lt;/P&gt;&lt;P&gt;The following Python script ran successfully about 3 weeks ago.&lt;/P&gt;&lt;P&gt;I wrote the script in Notepad. Then saved it from the Field Calculator.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Load it today and I get: Error 000539: Runtime error Syntax Error: encoding declaration in Unicode string (&amp;lt;string&amp;gt;, line 0)&lt;/P&gt;&lt;P&gt;Notepad shows the file is encoded UTF-16 LE. I have read that Python uses UTF-8 by default. I have tried (based on suggestions on other forums) using a coding syntax like:&lt;/P&gt;&lt;P&gt;# _*_ coding: UTF-16 LE _*_&amp;nbsp;&lt;/P&gt;&lt;P&gt;in first line of the Pre-Logic Script Code but that doesn't work and I don't really know what I am doing with that.&lt;/P&gt;&lt;P&gt;Seems like something basic is fouling the script up. Thanks for your suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached: screen shot of the Field Calculator window.&lt;/P&gt;&lt;P&gt;Script:&lt;/P&gt;&lt;P&gt;def Blockname(Species):&lt;BR /&gt;if Species = "Olneya tesota":&lt;BR /&gt;return "PINV-OT"&lt;BR /&gt;elif&amp;nbsp; Species = "Parkinsonia florida":&lt;BR /&gt;return "PINV-PF&lt;BR /&gt;elif Species =&amp;nbsp; "Parkinsonia microphylla":&lt;BR /&gt;return "PINV-PM&lt;BR /&gt;else:&lt;BR /&gt;return "NA"&lt;BR /&gt;__esri_field_calculator_splitter__&lt;BR /&gt;Blockname(!Species!)&lt;/P&gt;</description>
      <pubDate>Sun, 12 Sep 2021 01:11:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1097447#M62356</guid>
      <dc:creator>BenWilder</dc:creator>
      <dc:date>2021-09-12T01:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using code block with Field Calculator error 000539</title>
      <link>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1097451#M62357</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;use Notepad ++&amp;nbsp;&lt;A href="https://notepad-plus-plus.org/downloads/v8.1.4/" target="_blank"&gt;Notepad++ 8.1.4 release | Notepad++ (notepad-plus-plus.org)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;you can set it to interpret and save a python encoded files&lt;/P&gt;&lt;P&gt;use&amp;nbsp;&lt;SPAN&gt;UTF-8 or just dump the line period, but check the encoding to utf-8 in notepad&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Sep 2021 00:28:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1097451#M62357</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-09-12T00:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using code block with Field Calculator error 000539</title>
      <link>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1097454#M62358</link>
      <description>Thank you, Dan!&lt;BR /&gt;I typically, have these files saved with the .cal extension so I can load them in Field Calculator.&lt;BR /&gt;I tried saving the file out of Notepad++ to a .cal file. That doesn't work.&lt;BR /&gt;I can copy the code block from either Notepad++ or Notepad and the script runs normally.&lt;BR /&gt;Thank you for pointing me in the right direction.&lt;BR /&gt;</description>
      <pubDate>Sun, 12 Sep 2021 01:03:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1097454#M62358</guid>
      <dc:creator>BenWilder</dc:creator>
      <dc:date>2021-09-12T01:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using code block with Field Calculator error 000539</title>
      <link>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1123188#M63158</link>
      <description>&lt;P&gt;Hi Ben, did you ever manage to save the expression as a .cal file? I ran into this same issue today, with a field calculator expression that I've been using for the last 2 years saved as a .cal file on my desktop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 23:18:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1123188#M63158</guid>
      <dc:creator>LukeAllen2</dc:creator>
      <dc:date>2021-12-06T23:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using code block with Field Calculator error 000539</title>
      <link>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1123237#M63159</link>
      <description>Hi Luke,&lt;BR /&gt;No, I have never been able to get saved .cal files to work. I have to copy and paste out of Notepad like Dan suggested.&lt;BR /&gt;Thanks for asking.&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Dec 2021 03:21:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1123237#M63159</guid>
      <dc:creator>BenWilder</dc:creator>
      <dc:date>2021-12-07T03:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using code block with Field Calculator error 000539</title>
      <link>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1123337#M63162</link>
      <description>&lt;P&gt;Hi, Ben (just in case you haven't already tried this) you may want to try pasting it in from notepad ++ again and just saving out a new .cal file, when I did this I no longer had issues, which made me think perhaps I unknowingly introduced something into the .cal file one time or saved it incorrectly, worth a shot if you haven't already tried. Seems to have worked for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Luke&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 14:39:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-code-block-with-field-calculator-error/m-p/1123337#M63162</guid>
      <dc:creator>LukeAllen2</dc:creator>
      <dc:date>2021-12-07T14:39:45Z</dc:date>
    </item>
  </channel>
</rss>

