Using Python in Field Calculator

1801
5
Jump to solution
09-23-2010 09:46 AM
BrianElliott
New Contributor
How can I get this simple code to work using python in the field calculator? I cannot get the syntax correct to save my life.

if (!Shape_Area! / 2000) - (math.trunc (!Shape_Area! / 2000) + 1) = 0:
EQ = (!Shape_Area! / 2000) * 30
else:
EQ = (truncate ((!Shape_Area! / 2000) + 1) * 30

I can't get passed the first line without a syntax error.

I would love any help on this,
thanks
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus
tested on a shapefile not a geodatabase

View solution in original post

0 Kudos
5 Replies
BrianElliott
New Contributor
I did not copy all of the code correctly. Still cannot get passed first line of code...

if (!Shape_Area! / 2000) - math.trunc((!Shape_Area! / 2000) + 1) == 0:
EQ = (!Shape_Area! / 2000) * 30
else:
EQ = math.trunc((!Shape_Area! / 2000) + 1) * 30
0 Kudos
GerryGabrisch
Occasional Contributor III
Assuming the indentations are correct, you don't use the ! in the code itself, and you need == not =.
See the link below.
Good luck

if (Shape_Area / 2000) - (math.trunc (Shape_Area / 2000) + 1) == 0:


www.esri.com/news/arcuser/0507/files/pythonscript.pdf
0 Kudos
DanPatterson_Retired
MVP Emeritus
tested on a shapefile not a geodatabase
0 Kudos
BrianElliott
New Contributor
THANKS DAN!!!

I need to learn more about python, obviously.  Your code worked perfectly.
Now I can go get a beer. 🙂
0 Kudos
DanPatterson_Retired
MVP Emeritus
pass one through the screen
0 Kudos