From the course: Learning ArcGIS Python Scripting

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Conditional statements

Conditional statements

- [Instructor] Sometimes you need your Python code to stop and make a decision before moving on. For example, suppose you write a Python script that's going to run the erase geoprocessing tool which requires at least a standard ArcGIS Pro license. How do you make sure the script doesn't try to run the erase tool unless the user has a license to run it? Well, you could use a conditional statement, sometimes called an if-then statement. If statements let you control the flow of your script, you can use them to check that a feature class' properties match what you expect, check that projects exist before you try to use them, or check that methods return values that you can use in your script. For example, suppose your script "Ask the user for a road name," then it checks to see if a road name was entered. Did you get a value from them? Yes, okay, good. Try to select the road. No, ask them again. "Hey, you didn't give me the name of a road." So the syntax for an if statement looks like…

Contents