I have a PYTHON script that works in 10.3 but will not work now in 10.4. Anyone know why?
Solved! Go to Solution.
The error message indicates a character encoding problem with the !SPCOMP! field. You might try a decode to ascii. Also, I think your indexing to get "90" in your example should be 2 and 5 not 3 and 6.
def getPJ(spcomb):
if 'PJ' in spcomb:
n = spcomb.find('PJ')
return spcomb[n+2:n+5].strip()
else:
return 0
getPJ( !SPCOMP!.decode('ascii') )
Can you share the script (at least the part that is generating the error) and the error message?
I am attempting to write a script where I have a field called SPCOMP containing info such as "PJ 90BW 10". I am trying to pull the numbers and put them in respective fields. E.G. A field called PJ would be populated with the number 90. I had it work once, but now I am receiving this error - ERROR 000539: Runtime error SyntaxError: encoding declaration in Unicode string (<string>, line0). Here is the code I am Using
def getPJ(spcomb):
if 'PJ' in spcomb:
n = spcomb.find('PJ')
return spcomb[n+3:n+6]
else:
return 0
PJ =
getPJ( !SPCOMP! )
trying reposting you code using https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?s... so we can rule out tabs/spacing as being the issue since Python is very particular about that.
Make sure if you had any special libraries/mods that you were using, that you copied those over to the new location for 10.4 (i.e. path).
Also, how are you running this script? As a custom tool, in the ArcGIS Desktop/Catalog python window, as a standalone exe, or in an external python IDE? If anything but as a tool or Desktop, it may be a path issue.
I am attempting to write a script where I have a field called SPCOMP containing info such as "PJ 90BW 10". I am trying to pull the numbers and put them in respective fields. E.G. A field called PJ would be populated with the number 90. I had it work once, but now I am receiving this error - ERROR 000539: Runtime error SyntaxError: encoding declaration in Unicode string (, line0). I am running this straight from the field calculator. Attached is the code
The error message indicates a character encoding problem with the !SPCOMP! field. You might try a decode to ascii. Also, I think your indexing to get "90" in your example should be 2 and 5 not 3 and 6.
def getPJ(spcomb):
if 'PJ' in spcomb:
n = spcomb.find('PJ')
return spcomb[n+2:n+5].strip()
else:
return 0
getPJ( !SPCOMP!.decode('ascii') )
Thank you very much this worked!
Brent