Hi Richard,

The issue is with package foobar containing __main__.py file (not with a
module called as a script, which is your case), and called via python -m
foobar

See the last paragraph of https://docs.python.org/3/library/__main__.html :

«
For a package, the same effect can be achieved by including a
__main__.py module,
the contents of which will be executed when the module is run with -m.
»

Best regards,
Michaël

Le ven. 23 août 2019 22:32, Richard Musil <[email protected]> a écrit :

> Hello Michaël,
>
> in your PEP your wrote:
> ---
> The standard library's ``argparse.ArgumentParser`` uses by default
> ``sys.argv[0]`` for his ``prog`` property.
>
> It means that when using the ``python -m foobar`` invocation, which calls
> under
> the hood the ``foobar.__main__`` module, the ``prog`` will be
> ``__main__.py``,
> giving as usage: ``usage: __main__.py [-h] ...``.
> ---
> I did a quick check with the file `prog_name.py` which contained:
>
> if __name__ == '__main__':
>     from argparse import ArgumentParser
>     ap = ArgumentParser(description='Test default prog name')
>     args = ap.parse_args()
>
> then put it on PYTHONPATH and invoked it with:
> python -m prog_name --help
>
> and got the correct reply:
> usage: prog_name.py [-h]
>
> Test default prog name
>
> optional arguments:
>   -h, --help  show this help message and exit
>
> I checked on Python 3.7.3 (Windows) and Python 2.7.13 (raspbian), on both
> systems it behaves the same way.
> In what environment exactly do you see the problem?
>
> Richard
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/B3P7ZDYKWJUEC4SFRQMB2MARRN7MNWTA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to