I am trying to edit the basic sequential numbers in a field script using Python in the Field Calculator.

I set the Parser to Python, and for my Pre-logic Script:

def autoIncrement(): 
 global rec 
 pStart = 1  
 pInterval = 1 
 if (rec == 0):  
  rec = pStart  
  rec += pInterval  
 return name, rec

And for the box below:


Would this not be how to go about this?

Essentially I just want "manhole1" then "manhole2" then "manhole3", etc.

  • 2
    That code will put sequential numbers in the fields. If you want to add manhole to it, and it is a string field, just field calculate "manhole" + "numberfield" – Maksim Jun 27 '18 at 15:33
  • 'Manhole %s' %autoincrement() is one of solutions. Remove name from script. – FelixIP Jun 27 '18 at 19:15

A field calculator expression using pre-logic code should have a function called that, in the end, returns a single value each time the function is called. Currently, you are returning two separate values. To return a single value, you should be able to take your code above and change the line from return name, rec to return 'name' + str(rec)

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