4

I am trying to run a field calculator python script that will take a value from one field in the attributes table and create an abbreviation in another field that was designated for it.

Here is a example of the code that was written for this function:

enter image description here

def checkValue(c,d):
 if c == 'ARTERIAL_CRACKSEAL':
 return 'ACS'

The problem is that once I created coded value domains for these attributes the code stopped working (i.e. code:1 description: ARTERIAL_CRACKSEAL ; code:2 description ARTERIAL_microseal ; etc.). Would anyone know how to adjust the code so the script runs successfully? I need to keep coded value domains for this attribute field.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 8, 2016 at 17:59
1
  • 1
    Please edit your question to include your code as text rather than just as an image. Code as text makes it easier for potential answerers to copy/paste your code snippet to test, instead of having to type it all out manually. Commented Sep 8, 2016 at 18:06

1 Answer 1

6

In a coded value domain, the values are stored as 1, 2, 3 and not as ARTERIAL_CRACKSEAL, ARTERIAL_MICROSEAL, ARTERIAL_OVERLAY.

To make your code work with the coded values, change your if lines to refer to the codes:

def checkValue(c, d):
 if c == 1:
 return 'ACS'
 if c == 2:
 return 'AMS'
 if c == 3:
 return 'AOL'
 if c == 4:
 return 'TRM'
 if c == 5:
 return 'FST'
answered Sep 8, 2016 at 18:10
5
  • I have tried that as well and it did not seem to work unfortunately. Commented Sep 8, 2016 at 18:17
  • What errors did it return? can you include a screenshot of your domain settings and some of your data? Commented Sep 8, 2016 at 18:19
  • 1
    You may have already checked this, but make sure the types of your coded values and values in your script match. In this example, make sure your coded values are stored as integers and not characters. Commented Sep 8, 2016 at 18:22
  • I have tried it again by using the coded values instead of the description and including quotation marks around them. It worked fine this time, so your first answer was correct. I'm not sure if it was just the quotation marks or I did something else when I tried yesterday. Thank you for your help. Commented Sep 8, 2016 at 20:50
  • 1
    @DavorRomic if this has worked for you, please consider marking it as the answer. See What should I do when someone answers my question? Commented Sep 9, 2016 at 0:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.