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!
        return 0

Old_Far =


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 Answer 1


Try changing your calculation like this.

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

Then call it like this:

  • 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
    Commented 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
    Commented 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
    Commented Jun 4, 2013 at 16:39

Your Answer

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

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