In this video, Jennifer Harrison demonstrates how to make a script accept command-line arguments. Learn the syntax for using the sys.argv list and the GetParameterAsText list.
- [Instructor] ArcPy's sys module allows scripts…to accept command line arguments, also called parameters.…Let's see how to write a script…that accepts and makes use of parameters.…Since this is just little demo script…to show how command line arguments work,…I'm gonna skip all the niceties of a comment block…and sudo code.…To use the Python sys way of grabbing the parameters,…the sys module has to be imported.…Once the script has access to the sys module,…the argv list is available.…
So the first thing I'll do is to…import the sys module in my script.…Now I have access to the argv list.…I can just use it.…I'll print the first argument…you entered is sys.argv sub one.…And then I'll print the second argument you entered,…the sys.argv sub two.…
By the way, there is a zero element in this list,…sys.argv sub zero,…but it's always the name of the script that's being run.…So I'll save this script.…Now the problem is this script can't be run in IDLE…because there's no way to enter…command line arguments in IDLE.…Other IDEs allow it, but not IDLE.…
- 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.