Mike Driscoll
Mike Driscoll

@driscollis

8 Tweets Jan 28, 2023
Today is a great day to learn about #Python's `argparse` module!
The argparse module makes it easy to write user-friendly command-line interfaces.
#PythonStdLib ๐Ÿ๐Ÿ”ฅ
๐Ÿงต๐Ÿ‘‡
Here is an example of creating an argument parser with no arguments.
Why would you do that? Well, to find out what `argparse` gives you out of the box ๐Ÿ“ฆ!
You can see here that `argparse` gives you some help text and prints out your provided description
A common coding pattern for argument parsing is to put the argument parsing code into its own function or method and then return the parsed args.
Here's an example:
Let's add some arguments to our argument parser! In this example, you add one required argument and two optional arguments.
One of the optional arguments shows you how to apply a default value while the other only accepts integers
You can use short argument flags or long argument flags with #Python's `argparse` module ๐Ÿ๐Ÿ”ฅ
This thread only scratches the surface of what you can do with Python's `argparse` module.
Check out the docs for lots more detail:
docs.python.org
Thanks for checking out my thread on argument parsing with #Python ๐Ÿ๐Ÿš€
Follow me to learn more about the Python programming language!

Loading suggestions...