|
| https://realpython.com/ |
| Start Here | https://realpython.com/start-here/ |
|
Learn Python
| https://realpython.com/lessons/python-argparse-summary/ |
| Python Tutorials →In-depth articles and video courses | https://realpython.com/search?kind=article&kind=course&order=newest |
| Learning Paths →Guided study plans for accelerated learning | https://realpython.com/learning-paths/ |
| Quizzes & Exercises →Check your learning progress | https://realpython.com/quizzes/ |
| Browse Topics →Focus on a specific area or skill level | https://realpython.com/tutorials/all/ |
| Community Chat →Learn with other Pythonistas | https://realpython.com/community/ |
| Office Hours →Live Q&A calls with Python experts | https://realpython.com/office-hours/ |
| Podcast →Hear what’s new in the world of Python | https://realpython.com/podcasts/rpp/ |
| Books →Round out your knowledge and learn offline | https://realpython.com/products/books/ |
| Reference →Concise definitions for common Python terms | https://realpython.com/ref/ |
| Code Mentor →BetaPersonalized code assistance & learning tools | https://realpython.com/mentor/ |
| Unlock All Content → | https://realpython.com/account/join/ |
|
More
| https://realpython.com/lessons/python-argparse-summary/ |
| Learner Stories | https://realpython.com/learner-stories/ |
| Python Newsletter | https://realpython.com/newsletter/ |
| Python Job Board | https://www.pythonjobshq.com |
| Meet the Team | https://realpython.com/team/ |
| Become a Tutorial Writer | https://realpython.com/write-for-us/ |
| Become a Video Instructor | https://realpython.com/become-an-instructor/ |
| Search | https://realpython.com/search |
| https://realpython.com/search |
| Join | https://realpython.com/account/join/ |
| Sign‑In | https://realpython.com/account/login/?next=%2Flessons%2Fpython-argparse-summary%2F |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-argparse-command-line-interfaces |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-argparse-command-line-interfaces |
| https://realpython.com/courses/python-argparse-command-line-interfaces/#team |
| Building Command Line Interfaces With argparse | https://realpython.com/courses/python-argparse-command-line-interfaces/ |
| Christopher Trudeau | https://realpython.com/courses/python-argparse-command-line-interfaces/#team |
| Recommended Tutorial | https://realpython.com/command-line-interfaces-python-argparse/ |
| Course Slides (.pdf) | https://realpython.com/courses/python-argparse-command-line-interfaces/downloads/python-argparse-command-line-interfaces-slides/ |
| Sample Code (.zip) | https://realpython.com/courses/python-argparse-command-line-interfaces/downloads/python-argparse-command-line-interfaces-code/ |
| Ask a Question | https://realpython.com/lessons/python-argparse-summary/#discussion |
| https://realpython.com/feedback/survey/course/python-argparse-command-line-interfaces/liked/?from=lesson-title |
| https://realpython.com/feedback/survey/course/python-argparse-command-line-interfaces/disliked/?from=lesson-title |
| Contents | https://realpython.com/lessons/python-argparse-summary/#description |
| Transcript | https://realpython.com/lessons/python-argparse-summary/#transcript |
| Discussion (8) | https://realpython.com/lessons/python-argparse-summary/#discussion |
| official documentation | https://docs.python.org/3/library/argparse.html |
| how-to guide | https://docs.python.org/3/howto/argparse.html |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson_preview&utm_content=python-argparse-command-line-interfaces |
| Sign-In | https://realpython.com/account/login/ |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson_preview&utm_content=python-argparse-command-line-interfaces |
| Sign-In | https://realpython.com/account/login/ |
| 00:00 | https://realpython.com/lessons/python-argparse-summary/#t=0.68 |
| In the previous lesson, I showed you how to build a sub-parser. In this lesson, | https://realpython.com/lessons/python-argparse-summary/#t=0.68 |
| I’ll summarize the course and point you at some other command line parsing | https://realpython.com/lessons/python-argparse-summary/#t=4.41 |
| libraries. In this course, | https://realpython.com/lessons/python-argparse-summary/#t=7.82 |
| you learned all about the command line argument parser built into the Python | https://realpython.com/lessons/python-argparse-summary/#t=11.43 |
| standard library, called argparse. | https://realpython.com/lessons/python-argparse-summary/#t=14.97 |
| 00:17 | https://realpython.com/lessons/python-argparse-summary/#t=17.52 |
| This library supports both positional arguments as well as optional flags. | https://realpython.com/lessons/python-argparse-summary/#t=17.52 |
| It automatically generates help information, creating a -h flag for you. | https://realpython.com/lessons/python-argparse-summary/#t=22.71 |
| 00:28 | https://realpython.com/lessons/python-argparse-summary/#t=28.17 |
| You can modify how arguments are stored using the action parameter. | https://realpython.com/lessons/python-argparse-summary/#t=28.17 |
| This allows you to convert command line strings into numbers, use Boolean flags, | https://realpython.com/lessons/python-argparse-summary/#t=32.02 |
| and more. | https://realpython.com/lessons/python-argparse-summary/#t=36.49 |
| 00:37 | https://realpython.com/lessons/python-argparse-summary/#t=37.86 |
| You can also control how many parameters are consumed by your arguments through | https://realpython.com/lessons/python-argparse-summary/#t=37.86 |
| the use of | https://realpython.com/lessons/python-argparse-summary/#t=41.72 |
| nargs. nargs supports specific numbers of arguments or | https://realpython.com/lessons/python-argparse-summary/#t=42.62 |
| variable numbers of arguments with the special symbols *, +, | https://realpython.com/lessons/python-argparse-summary/#t=47.72 |
| and ?. argparse is pretty powerful, | https://realpython.com/lessons/python-argparse-summary/#t=51.14 |
| allowing all sorts of fine-grain control. | https://realpython.com/lessons/python-argparse-summary/#t=55.93 |
| 00:58 | https://realpython.com/lessons/python-argparse-summary/#t=58.39 |
| You can even specify that an argument must be one of a given set of choices, | https://realpython.com/lessons/python-argparse-summary/#t=58.39 |
| or you can create mutually exclusive groups of flags. | https://realpython.com/lessons/python-argparse-summary/#t=63.45 |
| Tired of typing | https://realpython.com/lessons/python-argparse-summary/#t=67.88 |
| all those arguments over and over? Built into the parser is a way of reading | https://realpython.com/lessons/python-argparse-summary/#t=68.59 |
| arguments from a file. This is done with an argument prefix, | https://realpython.com/lessons/python-argparse-summary/#t=72.43 |
| which is often set the @ symbol. | https://realpython.com/lessons/python-argparse-summary/#t=75.88 |
| 01:19 | https://realpython.com/lessons/python-argparse-summary/#t=79.57 |
| In addition to using the type parameter to convert command line strings into | https://realpython.com/lessons/python-argparse-summary/#t=79.57 |
| integers, you can also use any callable. | https://realpython.com/lessons/python-argparse-summary/#t=83.55 |
| This allows you to do fancier things, like directly convert the argument into a | https://realpython.com/lessons/python-argparse-summary/#t=86.42 |
| pathlib object. Although argparse comes with many storage actions, | https://realpython.com/lessons/python-argparse-summary/#t=90.63 |
| you can also write your own if you need something fancier. And finally, | https://realpython.com/lessons/python-argparse-summary/#t=95.5 |
| in the previous lesson, I covered how to use argparse to create sub-parsers. | https://realpython.com/lessons/python-argparse-summary/#t=100.05 |
| 01:44 | https://realpython.com/lessons/python-argparse-summary/#t=104.1 |
| This allows you to have your programs take commands similar to how Git | https://realpython.com/lessons/python-argparse-summary/#t=104.1 |
| uses checkout, status, and more. | https://realpython.com/lessons/python-argparse-summary/#t=108.86 |
| 01:53 | https://realpython.com/lessons/python-argparse-summary/#t=113.43 |
| argparse is a pretty deep library. It’s very well documented, | https://realpython.com/lessons/python-argparse-summary/#t=113.43 |
| and there is also a how-to guide available at the Python site | https://realpython.com/lessons/python-argparse-summary/#t=116.59 |
| if you want to read the details. | https://realpython.com/lessons/python-argparse-summary/#t=120.03 |
| 02:02 | https://realpython.com/lessons/python-argparse-summary/#t=122.6 |
| There are also several libraries out there to make argument management require | https://realpython.com/lessons/python-argparse-summary/#t=122.6 |
| less code than argparse. One of the most popular is called Click. | https://realpython.com/lessons/python-argparse-summary/#t=125.99 |
| 02:10 | https://realpython.com/lessons/python-argparse-summary/#t=130.25 |
| It uses function decorators to create subcommands., | https://realpython.com/lessons/python-argparse-summary/#t=130.25 |
| meaning there is less code necessary to write per sub-parser equivalent. | https://realpython.com/lessons/python-argparse-summary/#t=133.15 |
| 02:18 | https://realpython.com/lessons/python-argparse-summary/#t=138.35 |
| Another popular library is docopt, | https://realpython.com/lessons/python-argparse-summary/#t=138.35 |
| where you use docstrings to define your command line interface. | https://realpython.com/lessons/python-argparse-summary/#t=140.89 |
| 02:25 | https://realpython.com/lessons/python-argparse-summary/#t=145.38 |
| And if you want a summary, | https://realpython.com/lessons/python-argparse-summary/#t=145.38 |
| this article compares those two libraries with argparse so that you can choose | https://realpython.com/lessons/python-argparse-summary/#t=146.55 |
| which is best for your situation. | https://realpython.com/lessons/python-argparse-summary/#t=151.04 |
| 02:35 | https://realpython.com/lessons/python-argparse-summary/#t=155.82 |
| That’s all for me. | https://realpython.com/lessons/python-argparse-summary/#t=155.82 |
| I hope you found this course valuable. In the words of Siskel and Ebert, | https://realpython.com/lessons/python-argparse-summary/#t=157.0 |
| I’ll see you at the movies. | https://realpython.com/lessons/python-argparse-summary/#t=160.83 |
| Sept. 8, 2022 | https://realpython.com/lessons/python-argparse-summary/#comment-1e4db929-ff52-4ee7-b0c6-1af77d641487 |
| Sept. 9, 2022 | https://realpython.com/lessons/python-argparse-summary/#comment-dc068dd0-271e-46b6-953d-c41030ddccaf |
| Oct. 3, 2022 | https://realpython.com/lessons/python-argparse-summary/#comment-fbdf1f25-3b29-45a7-b67f-07347ef906b3 |
| Oct. 3, 2022 | https://realpython.com/lessons/python-argparse-summary/#comment-9a0d8c2c-2941-413f-898c-c1daed830725 |
| Dec. 21, 2023 | https://realpython.com/lessons/python-argparse-summary/#comment-1f707a72-b6d9-49ef-8198-2b962d766a82 |
| Dec. 21, 2023 | https://realpython.com/lessons/python-argparse-summary/#comment-753f45b4-78bc-475f-bfea-ebc066114375 |
| stackoverflow.com/questions/18160078/how-do-you-write-tests-for-the-argparse-portion-of-a-python-module | https://stackoverflow.com/questions/18160078/how-do-you-write-tests-for-the-argparse-portion-of-a-python-module |
| May 7, 2024 | https://realpython.com/lessons/python-argparse-summary/#comment-f93a6d21-ec0b-4fff-ad47-7605bbe85dac |
| May 8, 2024 | https://realpython.com/lessons/python-argparse-summary/#comment-b0ef5d80-ed8b-4d8a-9e4e-e8d191aff792 |
| Become a Member | https://realpython.com/account/join/ |
| https://realpython.com/lessons/building-command-line-interfaces-with-argparse-quiz/ |
| Overview | https://realpython.com/courses/python-argparse-command-line-interfaces/ |
|
Command Line Interfaces With argparse (Overview) 02:52
| https://realpython.com/videos/python-argparse-overview/ |
|
The Basics of argparse 04:54
| https://realpython.com/videos/argparse-basics/ |
|
Help and Positional vs Optional Arguments 09:25
| https://realpython.com/lessons/help-positional-optional-arguments/ |
|
Available Actions 07:41
| https://realpython.com/lessons/available-actions/ |
|
Multiplicity 05:28
| https://realpython.com/lessons/argparse-multiplicity/ |
|
Less Common Features 06:29
| https://realpython.com/lessons/less-common-features/ |
|
Callable Types and Custom Actions 05:33
| https://realpython.com/lessons/callable-types-custom-actions/ |
|
Sub-parsers 06:43
| https://realpython.com/lessons/subparsers/ |
|
Building Command Line Interfaces With argparse (Quiz) 11:30
| https://realpython.com/lessons/building-command-line-interfaces-with-argparse-quiz/ |
|
Command Line Interfaces With argparse (Summary) 02:43
| https://realpython.com/lessons/python-argparse-summary/ |
| Privacy Policy | https://realpython.com/privacy-policy/ |
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover