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]
That is what i am getting and not the caclulated value in the field.
I am new to this and trying to learn.
-
1It'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.Vince– Vince2023年02月16日 13:20:43 +00:00Commented Feb 16, 2023 at 13:20
-
1Can you explain what you are trying to do? For example how does your input attribute table look like, and what is your expected output`?Bera– Bera2023年02月16日 13:29:55 +00:00Commented 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)...J.R– J.R2023年02月16日 13:51:30 +00:00Commented Feb 16, 2023 at 13:51
1 Answer 1
I got it!
func(!Form_Name!)
def func(input):
if "_" in input:
return input.split("_")[1]
elif '_'in input:
return 'Yes'
else:
return ''
-
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:
Fezter– Fezter2023年03月03日 01:10:58 +00:00Commented Mar 3, 2023 at 1:10
Explore related questions
See similar questions with these tags.