Skip to content

Instantly share code, notes, and snippets.

@ariel-co
Created March 30, 2024 23:01
Show Gist options
  • Select an option

  • Save ariel-co/64ab6256045b39ee42c61a32ef5d3680 to your computer and use it in GitHub Desktop.

Select an option

Save ariel-co/64ab6256045b39ee42c61a32ef5d3680 to your computer and use it in GitHub Desktop.
argparser.ArgumentParser subclass that prints error message automatically
class MyArgParser(argparse.ArgumentParser):
def error(self, message):
print(f'Error: {message}\n', file=sys.stderr)
self.print_help()
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment