In this video, Jennifer Harrison explains how to use conditional statements to control the flow of a script. Learn how to use If statements with Python and ArcPy to check user input, check if files exist, and check ArcGIS desktop license levels.
- [Instructor] Sometimes you need your Python script to stop…and make a decision before moving on.…For example, suppose you write a Python script…that's gonna run the erase geoprocessing tool,…which requires at least a standard ArcMap license.…How do you check to see if the user has…at least a standard license?…You use a conditional statement, an if statement.…If statements let you control the flow of your script.…For example, suppose your script…asks the user for a road name,…and then it checks to see if a road name was entered.…
Did you get a value from them?…Yes?…Okay, try and select the road.…No?…Ask them to enter it again.…The syntax for an if statement looks like this…if some condition is true do something.…There's a colon at the end of the first line.…So if some condition is true do something,…else, do something else.…To make comparisons in an if statement,…you'll need some comparison operators.…
To compare if two values are equal…you use a double equal sign.…A single equal sign is always for variable assignment.…
- Writing and running Python scripts in IDLE
- Making scripts flexible with variables
- Commenting scripts
- Manipulating string data
- Object-oriented programming in Python
- Creating loops
- Reading and writing text files
- Capturing input at runtime
- Documenting your scripts
Skill Level Beginner
1. Python for ArcGIS Basics
2. Strings, Numbers, and Variables
Work with numeric values5m 22s
3. Syntax Rules
4. Manipulating Strings
5. Object-Oriented Programming
6. Using Loops
7. Generate Log Files
8. Input at Run Time
9. Help Documents
Documenting a script1m 59s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.