3 Replies Latest reply on Aug 15, 2011 6:05 AM by brumm1dj

    Python Field Calculate issue

    brumm1dj
      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//////
        • Re: Python Field Calculate issue
          lpugh01
          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.
          • Re: Python Field Calculate issue
            williamskg6
            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.
            • Re: Python Field Calculate issue
              brumm1dj
              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?