Calculating field with code block

972
5
Jump to solution
02-22-2022 12:09 AM
OriHarash
New Contributor II

Hi everybody,

Im trying to create a new field which will start with the value 1201 and increment by 1 until the end (82 values).

I have tried to use the code block to make it create such field but couldn't make it..

help please?  Tnx

0 Kudos
2 Solutions

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

You could use itertools.count

Expression:

next(counter)

Code block:

import itertools
counter = itertools.count(start=1201)

 

View solution in original post

Rakesh_Kumar_GIS
New Contributor III

Please create new field with "Double" 

Value

raka()

Code Block

rec=0
def raka():
global rec
pStart = 1201
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec += pInterval
return rec

View solution in original post

0 Kudos
5 Replies
Luke_Pinner
MVP Regular Contributor

You could use itertools.count

Expression:

next(counter)

Code block:

import itertools
counter = itertools.count(start=1201)

 

OriHarash
New Contributor II

cheers!

short and elegant. Do you  recommend to study the itertools ? 

 

0 Kudos
Rakesh_Kumar_GIS
New Contributor III

Please create new field with "Double" 

Value

raka()

Code Block

rec=0
def raka():
global rec
pStart = 1201
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec += pInterval
return rec

0 Kudos
OriHarash
New Contributor II

tnx man.. worked!

Rakesh_Kumar_GIS
New Contributor III

!!!!!!!!!!!!! 🙂 

0 Kudos