Select to view content in your preferred language

# Calculating field with code block

1195
5
02-22-2022 12:09 AM
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..

2 Solutions

Accepted Solutions
MVP Regular Contributor

You could use itertools.count

Expression:

next(counter)

Code block:

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

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

5 Replies
MVP Regular Contributor

You could use itertools.count

Expression:

next(counter)

Code block:

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

New Contributor II

cheers!

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

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

New Contributor II

tnx man.. worked!

New Contributor III

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