Python Field Calculate issue

1775
3
08-12-2011 11:13 AM
by Anonymous User
Not applicable
I am trying to use python inside of ArcMap to perform a field calculation. I am attempting to replace one word with another in my hyperlink field. My issue is that when I run the field calculator it replaces the words correctly, but it also changes the '\0' into little squares or question marks. I have tried using code blocks and writing the syntax differently but I keep getting the same result.

                       \\\\\\this is some example data\\\\\\\
\\gis1\GIS\Projects\Water\MidlandGTG\MidlandCity\Valves\Sec. 07\07-019.pdf
\\gis1\GIS\Projects\Water\MidlandGTG\MidlandCity\Valves\Sec. 07\07-020.pdf
\\gis1\GIS\Projects\Water\MidlandGTG\MidlandCity\Valves\Sec. 07\07-021.pdf
\\gis1\GIS\Projects\Water\MidlandGTG\MidlandCity\Valves\Sec. 07\07-022.pdf
\\gis1\GIS\Projects\Water\MidlandGTG\MidlandCity\Valves\Sec. 07\07707-002.pdf

!HYPERLINK!.replace("Projects","Data") //////this is the code I used//////
Tags (2)
0 Kudos
3 Replies
LoganPugh
Occasional Contributor III
Stick an r in front of !HYPERLINK! to tell it to parse it as a raw string instead of a normal string where backslashes are considered special characters.
0 Kudos
KentWilliams
New Contributor II
Stick an r in front of !HYPERLINK! to tell it to parse it as a raw string instead of a normal string where backslashes are considered special characters.


Either that or you can add another backslash where you currently have single backslashes.  The backslash \ character is the escape character in Python strings.  To get a backslash in a string you have to escape then backslash, so single string backslashes have to be converted to double backslashes in order for the actual string to have only one backslash character. 

Ex: The string "C:\Python.exe" will cause errors since you don't want an escape P character (whatever that is).  Convert the string to "C:\\Python.exe" and the actual string stored will have just the single backslash as you want.
0 Kudos
by Anonymous User
Not applicable
Stick an r in front of !HYPERLINK! to tell it to parse it as a raw string instead of a normal string where backslashes are considered special characters.


Awesome, thanks!! That did the trick.

  So is there a way to mark this issue solved?
0 Kudos