+ Reply to Thread
Results 1 to 4 of 4

Thread: Python Field Calculate issue

  1. #1
    Daniel Brumm
    Join Date
    Mar 2011
    Posts
    18
    Points
    0
    Answers Provided
    0


    0

    Unhappy Python Field Calculate issue

    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//////

  2. #2
    Logan Pugh
    Join Date
    May 2010
    Posts
    210
    Points
    27
    Answers Provided
    1


    0

    Default Re: Python Field Calculate issue

    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.

  3. #3
    Kenton Williams
    Join Date
    Aug 2010
    Posts
    5
    Points
    1
    Answers Provided
    0


    0

    Default Re: Python Field Calculate issue

    Quote Originally Posted by lpugh01 View Post
    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.

  4. #4
    Daniel Brumm
    Join Date
    Mar 2011
    Posts
    18
    Points
    0
    Answers Provided
    0


    0

    Thumbs up Re: Python Field Calculate issue

    Quote Originally Posted by lpugh01 View Post
    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?

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts