Select to view content in your preferred language

Newbie: Why wouldn't this simple code work?

717
2
Jump to solution
04-10-2012 11:10 AM
PeterPeng
Occasional Contributor
Purpose:
I have 1 field in a large table with numbers in mm, want to show in m. Want to use python to multiply by 1000. Want to use the Python Field Calculator for this.

Code:

def func( height ):  return (height*1000)



HEIGHT_MM= func(!HEIGHT_MM)


Result:
the code succeeds (no syntax errors), but nothing happens to the numbers in my field!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Alum
You need another exclamation mark around the field name. I'm a little bit surprised that it ran at all. It may be interpretting the one exclamation as "if HEIGHT_MM does not exist".

HEIGHT_MM= func(!HEIGHT_MM!)

View solution in original post

0 Kudos
2 Replies
DarrenWiens2
MVP Alum
You need another exclamation mark around the field name. I'm a little bit surprised that it ran at all. It may be interpretting the one exclamation as "if HEIGHT_MM does not exist".

HEIGHT_MM= func(!HEIGHT_MM!)
0 Kudos
BruceNielsen
Frequent Contributor
It should be:
HEIGHT_MM= func(!HEIGHT_MM!)
You're missing the trailing exclamation.
0 Kudos