0

I was trying to write and if calculation and I cannot figure out the syntax to complete it. The one on the left doesn’t work as it will return the text of the calculation I am trying to perform instead of the value. One on the right is the calculation that I want to use:

No =

func(!Form_Name!)

Code Block

def func(input):
 if '_' in input:
 return '!Form_Name!.split("_")[1]'
 elif '-'in input:
 return 'Yes'
 else:
 return 'No Match'

Calculation Formula I want to use:

!Form_Name!.split("_")[1]

enter image description here

That is what i am getting and not the caclulated value in the field.

I am new to this and trying to learn.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 16, 2023 at 13:09
3
  • 1
    It's part of a Calculate Field expression in ArcGIS Desktop, but the code is a bit odd, and possibly incomplete, and it looks like a literal is being returned instead of an evaluated expression. Commented Feb 16, 2023 at 13:20
  • 1
    Can you explain what you are trying to do? For example how does your input attribute table look like, and what is your expected output`? Commented Feb 16, 2023 at 13:29
  • I think the problem are the comma around the function for the first return (comma made it a string and not a fonction)... Commented Feb 16, 2023 at 13:51

1 Answer 1

2

I got it!

func(!Form_Name!)
def func(input):
 if "_" in input:
 return input.split("_")[1]
 elif '_'in input:
 return 'Yes'
 else:
 return ''
MrXsquared
36.2k22 gold badges76 silver badges127 bronze badges
answered Feb 16, 2023 at 17:28
1
  • The way you've written this is different to your original post. The first "elif" statement will never run because the condition is the same as the first one. Both checking for underscores. So, you'll never get "Yes" as an output. I assume in your actual code, it's written as elif '-' in input: Commented Mar 3, 2023 at 1:10

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.