Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

Try changing your calculation like this.

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

Then call it like this:

share|improve this answer
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 '13 at 12:40
Inside of the function, I don't know that you can. Why is passing more inputs a problem? – JeremyFon Jun 4 '13 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 '13 at 16:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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