Category: argparse

Problem

Parse command-line arguments with argparse.

Solution

  parser = argparse.ArgumentParser()
parser.add_argument("filename")
args = parser.parse_args()
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path