1

I have two fields showing number of people in two age groups "young" and "old". these people also live in a cell (point) whose distance to a specific facility is calculated. then I categorized these distances to two groups of "far" and "close".

Now, I want to create four new fields that the values of "Old_far" and "young_far" will the exact values of aforementioned population groups if the cell is located in the group of far, otherwise they will be zero and the values go to the field of "Old_close" and "Young_close". the code for a field I tried follows:

-for old_far:

def func(X):
    if X==2:
        return !old!
    else:
        return 0

Old_Far =

func(!distance_group!)

the code above returns an error of "exceptions.SyntaxError: Invalid syntax(Line 3)"

I want to reach the value of the "old" field of the same record. Should I some how reach the value of that field?

I am using ArcGIS Desktop 10.1.

1

1 Answer 1

1

Try changing your calculation like this.

def func(X,Old):
    if X==2:
        return Old
    else:
        return 0

Then call it like this:

func(!distance_group!,!old!)
3
  • yes, it works if I add more inputs. but the question is that how I can reach the other values of records without adding more inputs.
    – msc87
    Jun 3, 2013 at 12:40
  • Inside of the function, I don't know that you can. Why is passing more inputs a problem?
    – JeremyFon
    Jun 4, 2013 at 12:57
  • It is that I have to create several fields which depend on more than two fields and each one should calculate based on different combination of fields which makes it more complicated. So if the fields are accessible through an object I don't need need to change the inputs every time. And, I am also a bit curios :).
    – msc87
    Jun 4, 2013 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.