Commit b1a2abdb authored by Hai Shi's avatar Hai Shi Committed by Stéphane Wirtel

bpo-37908: Add an example of ArgumentParser.exit() (GH-15455)

Co-Authored-By: default avatarBrandt Bucher <brandtbucher@gmail.com>
parent 4210ad5e
...@@ -2029,7 +2029,14 @@ Exiting methods ...@@ -2029,7 +2029,14 @@ Exiting methods
.. method:: ArgumentParser.exit(status=0, message=None) .. method:: ArgumentParser.exit(status=0, message=None)
This method terminates the program, exiting with the specified *status* This method terminates the program, exiting with the specified *status*
and, if given, it prints a *message* before that. and, if given, it prints a *message* before that. The user can override
this method to handle these steps differently::
class ErrorCatchingArgumentParser(argparse.ArgumentParser):
def exit(self, status=0, message=None):
if status:
raise Exception(f'Exiting because of an error: {message}')
exit(status)
.. method:: ArgumentParser.error(message) .. method:: ArgumentParser.error(message)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment