Using ArcMap 10.8.1
The following Python script ran successfully about 3 weeks ago.
I wrote the script in Notepad. Then saved it from the Field Calculator.
Load it today and I get: Error 000539: Runtime error Syntax Error: encoding declaration in Unicode string (<string>, line 0)
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:
# _*_ coding: UTF-16 LE _*_
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.
Seems like something basic is fouling the script up. Thanks for your suggestions.
Attached: screen shot of the Field Calculator window.
Script:
def Blockname(Species):
if Species = "Olneya tesota":
return "PINV-OT"
elif Species = "Parkinsonia florida":
return "PINV-PF
elif Species = "Parkinsonia microphylla":
return "PINV-PM
else:
return "NA"
__esri_field_calculator_splitter__
Blockname(!Species!)
Solved! Go to Solution.
Code formatting ... the Community Version - Esri Community
use Notepad ++ Notepad++ 8.1.4 release | Notepad++ (notepad-plus-plus.org)
you can set it to interpret and save a python encoded files
use UTF-8 or just dump the line period, but check the encoding to utf-8 in notepad
Code formatting ... the Community Version - Esri Community
use Notepad ++ Notepad++ 8.1.4 release | Notepad++ (notepad-plus-plus.org)
you can set it to interpret and save a python encoded files
use UTF-8 or just dump the line period, but check the encoding to utf-8 in notepad
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.
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.
Luke