I need to convert this code to be used by python in ArcGIS

if [Field_1] < [Field_2] : pd = [Field_1] else: pd = [Field_2]

  • 7
    Welcome to GSE. I removed your "ASAP" since it generally slows response time. In the future, please be sure to provide complete software release information and a more robust description of the problem.
    – Vince
    May 11 '15 at 13:10

for a shorter code, you could use the built in "min" function to avoid the use of a code block. "min" can be used for more than one field.

if [Field_1] < [Field_2]:
     pd = [Field_1]
     pd = [Field_2]

In this example it is pretty simple. Look over this page for more examples on if statements.

If you are interested in learning more about utilizing Python in the GIS realm, please read this thread.

  • 6
    Depending on where you are entering this expression (i.e. Field calculator and other) you need to enclose your field names with ! instead of [] for use with Python. Also, be sure to handle the case where !Field_1! == !Field_2!. +1 for the links!
    – Martin
    May 11 '15 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.