Select to view content in your preferred language

Python. Simple script not working. Synthax error!!

654
1
03-05-2014 11:52 PM
jenkelly
New Contributor
I am looking to redefine the average height attribute as either 1 or 2 story depending on their height. Any height less than 4 = 1 storey house and height above 4 = 2 storey house.
Please see screenshot of script. Have not used python much before and any help would be appreciated.
Thanks[ATTACH=CONFIG]31973[/ATTACH]
Tags (2)
0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor
Hi Jen,

You're close. What is going wrong in your script is that in the definition of the  function you provide your field name, which contains a dot. What you  should provide is the name (any name) for a variable. In my example I  use "building_height" and "store_height".

As pre-logic script code you can use this (this includes logic for buildings that have more than 2 stories and being able to define the storey height):
def getStories(building_height, store_height):
    return "{0} storey".format(int(building_height / store_height) + 1)


The function is called like this:
getStories( !YourFieldName!, 4)


Please not that in this code 4 height units will return "1 storey", but 4.1 height units, will return "2 storey". I don't know if that is entirely correct...

Kind regards,

Xander
0 Kudos