Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am new to Phyton and currently trying to get my first script to work. Could someone tell me what is wrong with this code:


total = 0
def accumulate(increment):
 global total
 if total:
  if (total >= 1103):
    total = (total - 1103)
   else:
    total += increment
 else:
    total = increment
 return total

This one (the example from ESRI) works:


total = 0
def accumulate(increment):
 global total
 if total:
  total += increment
 else:
  total = increment
 return total

I am trying to run this code in Arcgis 10.1! Thanks so much!

share|improve this question

closed as too localized by whuber Mar 13 '13 at 17:01

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Your indentation on the first else does not seem to line up with the second if. If you use IDLE or another Python IDE to author your scripts it should take care of indentation automatically. Also, can you show us where you are calling your accumulate function from and any errors you are receiving, please? –  PolyGeo Mar 13 '13 at 10:19
    
Fantastic, Thank you PolyGeo! So simple... edit Ah, didn't see your edit.. I am calculating this inside the Field Calculator that loops through a List. Here is the call: accumulate( !WeaSMax_W! ) I just tried to find a way to skip accumulation of a field when a value is reached. It works now, thanks so much! –  Alex Mar 13 '13 at 10:26
add comment

1 Answer 1

up vote 2 down vote accepted

Your indentation on the first else does not seem to line up with the second if.

If you use IDLE or another Python IDE to author/test your scripts it should take care of indentation automatically.

You can then copy/paste them into the Field Calculator knowing that your Python syntax is right.

share|improve this answer
    
Finally I decided for PyScripter. Much better than Notepad++ for Phyton Code writing! Thanks for the hint. –  Alex Mar 14 '13 at 9:21
add comment

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