CalculateField_management generates ERROR 000539

815
2
11-17-2011 01:54 PM
WayneHajas
New Contributor
I am using ARCGIS 10.0.  I am trying to populate a field through CalculateField.

The approach I am trying now, is to build a stack-class to contain the values.  Then I can use a method from the stack-class as the function that goes into CalculateField.  My command looks like this:

[INDENT][/INDENT]gp.CalculateField_management(tmpcopy, 'temp', 'AsStack.GetVal())', 'PYTHON')

The resulting error message is:
[INDENT][/INDENT]ExecuteError: ERROR 000539: Error running expression: AsStack.GetVal()) <type 'exceptions.SyntaxError'>: unexpected EOF while parsing (<string>, line 1)
Failed to execute (CalculateField).

I have confirmed that AsStack.GetVal() gives the correct number of real-values between zero and one. 

I have found a couple of similar commands that do work:
[INDENT]gp.CalculateField_management(tmpcopy, "temp", 'numpy.random.rand()', "PYTHON")
[/INDENT]gp.CalculateField_management(tmpcopy, "temp", 'AsStack.nval', "PYTHON") (nval is just an integer value)

I am running out of things to try.  The calculations I am using do require an external library (rpy2).  I might be able to avoid the stack-class - but eventually I do think I will need to give CalculateField_managemen a method from a class as the python-expression.

Does anybody have a suggestion for what I should try next?

Thanks,
Wayne Hajas
Tags (2)
0 Kudos
2 Replies
WayneHajas
New Contributor
I managed to circumvent the problem.

I defined a new function:  def dummy():return(AsStack.GetVal())

gp.CalculateField_management(tmpcopy, "temp", 'dummy()', "PYTHON") works!

Things won't be as elegant as I hoped, but life is manageable once again.

Cheers,
Wayne
0 Kudos
WayneHajas
New Contributor
I was premature in declaring my stack-method to be a solution.  After all the pieces of my application were put together, CalculateField_management did not populate a field - it was just left blank without any error messages.

Fortunately I have discovered UpdateCursor and setValue.  They seem to work much more reliably.  They are likely not as efficient to use as CalculateField_management - when CalculateField_management works.

Due to the similarity in functionality of CalculateField and setValue, it would be great to have some cross referencing in arcpy.  It would have saved me a few hours.

Wayne Hajas
0 Kudos