Formula differences

767
2
Jump to solution
09-27-2012 04:41 AM
JamesCrandall
MVP Frequent Contributor
ArcGIS 9.3.1

I am attempting to calculate a field with a specific formula, which actually works correctly when I plug it into the FieldCalculator in ArcGIS 9.3.1 --- however, I am getting a different result when I place the formula into a Python script.

edit: "fff" is just a field that holds an incremental value starting at 1. 

This works in the Field Calculator:
40 - (Int(( [fff] - 1) / 35) + 1) + 1

My attempt to calc the field in the script is like:

rowsr = gp.UpdateCursor(outLabelsFC) rowr = rowsr.Next() i = 1 while row:       rowr.setvalue("row", (40 - ((rowr.fff - 1) / 35) + 1) + 1)       rowsr.updateRow(rowr)       i = i + 1       rowr = rowsr.Next() 


Python doesn't like the "Int", so I have tried:
40 - ((rowr.fff - 1) / 35) + 1) + 1
and...
40 - (long((rowr.fff - 1) / 35)) + 1) + 1

Both of the above generate a different result from run in the field calculator.  Can you help explain why or what I am missing here?

Thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NeilAyres
MVP Alum
Py is case sensitive so "Int" should be "int".
Then in your 2 calculation statements you a have mismatch in the brackets.
Have you tried testing this in the python ide directly.
Cheers,
N

View solution in original post

0 Kudos
2 Replies
NeilAyres
MVP Alum
Py is case sensitive so "Int" should be "int".
Then in your 2 calculation statements you a have mismatch in the brackets.
Have you tried testing this in the python ide directly.
Cheers,
N
0 Kudos
JamesCrandall
MVP Frequent Contributor
Py is case sensitive so "Int" should be "int".
Then in your 2 calculation statements you a have mismatch in the brackets.
Have you tried testing this in the python ide directly.
Cheers,
N


Thank you, Neil.

I simply needed to change Int to int.  Jumping from C#.NET/VB.NET to Python (I am new to Python) and creating Geoprocessing objects has been interesting.  Simple things can really trip you up and seem to be quite difficult to pickup for some reason!

Thanks again.
0 Kudos