Python calculation in field calculator

3221
4
10-17-2011 01:43 AM
KathrinSchulte-Braucks
New Contributor III
Hello,

I'm trying to do some simple calculation within the field calculator using Python instead of VB and keep on getting error messages.

Pre-logic script code:
def rad (value):
  return math.sqrt(value / math.pi( ) )


Expression:
AEQU_RAD= rad (!area!)

I get the error message, that "float object is not callable". Field type is double.
0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus
pi() is the problem, see below
>>> import math
>>> print math.pi
3.14159265359
>>> print math.pi()
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: 'float' object is not callable
0 Kudos
KathrinSchulte-Braucks
New Contributor III
Thank you so much, now it works. I just clicked on the proposed function in the box on the right. The implemented syntax in the box was math.pi(), so I assumed this is the correct syntax.
0 Kudos
ChrisFox3
Occasional Contributor III
Hi Kathrin,

Thank you for pointing out this issue. I logged a bug for math.pi and math.e constants being listed as functions in the field calculator, NIM074191.
0 Kudos
KathrinSchulte-Braucks
New Contributor III
Thanks for processing this issue!
0 Kudos