ArcPro 2.5 field calculator bug

1921
10
Jump to solution
05-01-2020 08:07 AM
PRuss
by
New Contributor III

"\\DPWTECHENG\Plat\" + !plat_book! + "_" + !plat_page! + ".tif"

throws an syntax error in ArcPro 2.5

"\\DPWTECHENG\Plat\ " + !plat_book! + "_" + !plat_page! + ".tif"

is valid in ArcPro 2.5 field calculator, the only difference is adding a space after \Plat\

Problem: We don't want that extra space after \Plat\

any ideas on when this bug will be fixed?

0 Kudos
1 Solution

Accepted Solutions
Katie_Clark
MVP Regular Contributor

I was playing around with this a bit, it seems to not like using r for a raw string. Instead, add another backslash as an escape character. (below is the code I used, so keep in mind I'm using all strings instead of referencing field names)

"\\\DPWTECHENG\Plat\\" + "plat_book" + "_" + "plat_page" + ".tif"

That validates for me, and the extra backslash isn't included in the output.

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek

View solution in original post

10 Replies
Katie_Clark
MVP Regular Contributor

I'm not sure, can you use raw strings in field calculator? That might help. 

Python Raw String - JournalDev 

Does this work for you? 

r"\\DPWTECHENG\Plat\" + !plat_book! + "_" + !plat_page! + ".tif"
Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
PRuss
by
New Contributor III

same syntax error trying 

r"\\DPWTECHENG\Plat\" + !plat_book! + "_" + !plat_page! + ".tif"
0 Kudos
Katie_Clark
MVP Regular Contributor

I was playing around with this a bit, it seems to not like using r for a raw string. Instead, add another backslash as an escape character. (below is the code I used, so keep in mind I'm using all strings instead of referencing field names)

"\\\DPWTECHENG\Plat\\" + "plat_book" + "_" + "plat_page" + ".tif"

That validates for me, and the extra backslash isn't included in the output.

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
PRuss
by
New Contributor III

interesting work around that delivers the correct output, i appreciate your help!

add another backslash as an escape character

i submitted this bug to: support.esri.com/en/report-bug

Katie_Clark
MVP Regular Contributor

Glad it helped!

For reference, here is a page on escape characters in Python: 

Python Escape Characters 

I'm not sure if this technically would qualify as a bug (not accepting raw strings in field calculator), but if you do get more relevant information from Esri regarding this, it would be awesome if you'd post back here with an update in case someone references this post in the future.

Cheers,

Katherine

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
PRuss
by
New Contributor III

It works fine in ArcMap using VBScript:

"\\DPWTECHENG\Plat\" + [plat_book] + "_" + [plat_book] + ".tif"

i have never understood why Pro did away with the VBScript option.... if something works better than alternatives why get rid of it?

Another ArcMap example doing something better than Pro:

Hyperlinks - after 1 input into attribute table they work flawlessly in ArcMap.

                in Pro one has to find workarounds for lack of a solid working language (VBScript) and add additional coding e.g. 

               "<a href="  +  [plat] + " target=_top>" +  [plat_book] + "_" + [plat_page]

                     and then once these 2 extra steps are done, there is a significant lag time when clicking the hyperlinks in Pro, often having to click them several times before they open.

 

I linked this thread to the Report Bug to highlight all of these Pro limitations that need to be fixed.

I know I am not the only one spending way too much time (many hours) diagnosing, finding workarounds, and documenting these unacceptable issues... Esri has had 5 years to get Pro to come correct, starting to think it is never going to happen.

 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Regarding:

i have never understood why Pro did away with the VBScript option

Esri did away with VBScript because the world is doing away with VBScript.  Although Microsoft hasn't formally retired VBScript, it has been an orphaned language that is dying a slow death for many years.  Microsoft itself has started disabling VBScript in components of Windows operating systems.

About:

if something works better than alternatives

I am not sure which alternatives you are referring to, but Pro offers support for Python and Arcade, and both are more robust already than VBScript ever was.  I personally don't like that Esri went and created yet another proprietary scripting language, but my dislike for what Esri did doesn't prevent me from seeing where the language has gotten in a relatively short time. And regarding Python, well, Python is one of the most popular scripting languages in the world and is incredibly robust and continuing to get better.

JoshuaBixby
MVP Esteemed Contributor

P Russ‌, the issue you are running into isn't a defect, either in Field Calculator or Python, it is a misunderstanding of the syntax for Python strings.

Although I support Katherine's suggestion on using raw strings for paths, her first suggestion using a raw string

>>> r"\\DPWTECHENG\Plat\" + !plat_book! + "_" + !plat_page! + ".tif"
  File "<stdin>", line 1
    r"\\DPWTECHENG\Plat\" + !plat_book! + "_" + !plat_page! + ".tif"
                                           ^
SyntaxError: invalid syntax
>>> 

was still invalid because a "a raw literal cannot end in a single backslash"  (2. Lexical analysis — Python 3.7.7 documentation ).  Although raw strings treat backslashes as normal characters, that doesn't apply when the backslash is the final character in a sequence.

Katie_Clark
MVP Regular Contributor

Joshua Bixby‌, thanks for adding your insight! I love when I actually learn something myself when helping others with their questions, it's the best part of Geonet  

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek