When using argparse in an executable module, the help message displays __main__.py instead of the module name. How to correct this?
$python -m mymodule -h
usage: __main__.py [-h]`
My executable python module
optional arguments:
-h, --help show this help message and exit
The instruction python -m mymodule runs the __main__.py script located in mymodule, this is why argparse uses __main__.py as program name (doc).
The program name can be overridden with the prog argument:
parser = argparse.ArgumentParser(
prog='python -m mymodule',
description='My executable python module.')
indeed:
$python -m mymodule -h
usage: python -m mymodule [-h]
My executable python module
optional arguments:
-h, --help show this help message and exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With