I have a PYTHON script that works in 10.3 but will not work now in 10.4. Anyone know why?
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.
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">getPJ</SPAN><SPAN class="punctuation token">(</SPAN>spcomb<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="string token">'PJ'</SPAN> <SPAN class="keyword token">in</SPAN> spcomb<SPAN class="punctuation token">:</SPAN> n <SPAN class="operator token">=</SPAN> spcomb<SPAN class="punctuation token">.</SPAN>find<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'PJ'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> spcomb<SPAN class="punctuation token">[</SPAN>n<SPAN class="operator token">+</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">:</SPAN>n<SPAN class="operator token">+</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>strip<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="number token">0</SPAN> getPJ<SPAN class="punctuation token">(</SPAN> !SPCOMP!<SPAN class="punctuation token">.</SPAN>decode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'ascii'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thank you very much this worked!
Brent
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
trying reposting you code using https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?sr=search&searchId=2d3e243c-22aa-4d75-9563-efa147c01ac8&searchIndex=0 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 (<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! )
Can you share the script (at least the part that is generating the error) and the error message?
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.