In this video, Jennifer Harrison explains how to make a script flexible enough to accept a varying number of command-line arguments. Learn how to grab command-line arguments in a list and to check how any arguments were entered.
- [Instructor] In Python, command line arguments…are captured in a list automatically.…They can be used in the script either by referencing them…by their list variable name,…or by assigning them to new variables.…Since they are captured in a list,…and this list can be expanded as needed,…it's easy to make the script flexible enough…to work on however many entries the user enters.…ArcMap does this with many of its tools.…Intersect, for example, allows you to enter…a whole list of feature classes as inputs.…
So I can browse out and get the BelizeBasemap dataset,…and intersect that with the EcologicalSystems.…The intersect tool doesn't have to know…how many entries I'm gonna make.…It's flexible enough to allow me to enter up to 50 datasets.…Python scripts can do this too by making use…of command line arguments and loops.…I'll make a quick script to accept…any number of command line arguments.…
Since this is just a demonstration script…that doesn't really do much, I won't bother…with a comment block or sudo code.…Argv is the list that we're gonna use.…
- 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.