Python and Field Calculator

744
4
06-18-2014 12:04 PM
LeonKincy
New Contributor II
I am trying to run the following Python script through Field Calculator

Parser:
Python

Expression:
calctemp(!Value!)

Code Block

def calctemp(newValue):

if newValue > 0:
   tempF = (newValue - 273.15)* 1.8000 + 32.00
return tempF

I get a syntax error invalid syntax(<expression>, line 1)

Any suggestions
Tags (2)
0 Kudos
4 Replies
MathewCoyle
Frequent Contributor
Make sure it is indented properly.

Pre-Logic Script Code:
def calctemp(newValue):
  if newValue > 0:
    tempF = (newValue - 273.15)* 1.8000 + 32.00
    return tempF
0 Kudos
LeonKincy
New Contributor II
I adjusted the indentations, but the error message persists.
0 Kudos
Zeke
by
Regular Contributor III
Maybe null (None in Python) values in your Value field?  Try changing the if statement to: if newValue is not None and newValue > 0:  return...etcAnother possibility: is Value a text field?These don't seem like syntax errors to me, but worth a shot. Maybe also check if Value is the real field name, and not an alias. Again not an expected error, but hey...
0 Kudos
LeonKincy
New Contributor II
I still have the error. I uploaded a portion of the data file. Value is long. There is one
thing I'm not sure about. Value and newValue are suppose to be interchangeable.
Value is external to calctemp and is used in the call to calctemp. While newValue is
used internally by calctemp.
0 Kudos