Python Projects & Skills / Working like a pro
Lesson 5 of 28
Command-line arguments
sys.argv holds the words typed after your script name. The argparse module turns them into proper options with help text.
Key points
- sys.argv[0] is the script name
- argparse adds --help for free
- Great for building tools
import argparse
p = argparse.ArgumentParser()
p.add_argument("name")
args = p.parse_args()
print("Hi", args.name)Quiz · +10 XP
Which module builds command-line options with help text?
Log in to save progress and earn XP.